1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <map> 11 12 // class map 13 14 // size_type count(const key_type& k) const; 15 16 #include <map> 17 #include <cassert> 18 19 #include "min_allocator.h" 20 #include "private_constructor.hpp" 21 22 int main() 23 { 24 { 25 typedef std::pair<const int, double> V; 26 typedef std::map<int, double> M; 27 { 28 typedef M::size_type R; 29 V ar[] = 30 { 31 V(5, 5), 32 V(6, 6), 33 V(7, 7), 34 V(8, 8), 35 V(9, 9), 36 V(10, 10), 37 V(11, 11), 38 V(12, 12) 39 }; 40 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 41 R r = m.count(5); 42 assert(r == 1); 43 r = m.count(6); 44 assert(r == 1); 45 r = m.count(7); 46 assert(r == 1); 47 r = m.count(8); 48 assert(r == 1); 49 r = m.count(9); 50 assert(r == 1); 51 r = m.count(10); 52 assert(r == 1); 53 r = m.count(11); 54 assert(r == 1); 55 r = m.count(12); 56 assert(r == 1); 57 r = m.count(4); 58 assert(r == 0); 59 } 60 } 61 #if __cplusplus >= 201103L 62 { 63 typedef std::pair<const int, double> V; 64 typedef std::map<int, double, std::less<int>, min_allocator<V>> M; 65 { 66 typedef M::size_type R; 67 V ar[] = 68 { 69 V(5, 5), 70 V(6, 6), 71 V(7, 7), 72 V(8, 8), 73 V(9, 9), 74 V(10, 10), 75 V(11, 11), 76 V(12, 12) 77 }; 78 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 79 R r = m.count(5); 80 assert(r == 1); 81 r = m.count(6); 82 assert(r == 1); 83 r = m.count(7); 84 assert(r == 1); 85 r = m.count(8); 86 assert(r == 1); 87 r = m.count(9); 88 assert(r == 1); 89 r = m.count(10); 90 assert(r == 1); 91 r = m.count(11); 92 assert(r == 1); 93 r = m.count(12); 94 assert(r == 1); 95 r = m.count(4); 96 assert(r == 0); 97 } 98 } 99 #endif 100 #if _LIBCPP_STD_VER > 11 101 { 102 typedef std::pair<const int, double> V; 103 typedef std::map<int, double, std::less <>> M; 104 typedef M::size_type R; 105 106 V ar[] = 107 { 108 V(5, 5), 109 V(6, 6), 110 V(7, 7), 111 V(8, 8), 112 V(9, 9), 113 V(10, 10), 114 V(11, 11), 115 V(12, 12) 116 }; 117 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 118 R r = m.count(5); 119 assert(r == 1); 120 r = m.count(6); 121 assert(r == 1); 122 r = m.count(7); 123 assert(r == 1); 124 r = m.count(8); 125 assert(r == 1); 126 r = m.count(9); 127 assert(r == 1); 128 r = m.count(10); 129 assert(r == 1); 130 r = m.count(11); 131 assert(r == 1); 132 r = m.count(12); 133 assert(r == 1); 134 r = m.count(4); 135 assert(r == 0); 136 } 137 138 { 139 typedef PrivateConstructor PC; 140 typedef std::map<PC, double, std::less<>> M; 141 typedef M::size_type R; 142 143 M m; 144 m [ PC::make(5) ] = 5; 145 m [ PC::make(6) ] = 6; 146 m [ PC::make(7) ] = 7; 147 m [ PC::make(8) ] = 8; 148 m [ PC::make(9) ] = 9; 149 m [ PC::make(10) ] = 10; 150 m [ PC::make(11) ] = 11; 151 m [ PC::make(12) ] = 12; 152 153 R r = m.count(5); 154 assert(r == 1); 155 r = m.count(6); 156 assert(r == 1); 157 r = m.count(7); 158 assert(r == 1); 159 r = m.count(8); 160 assert(r == 1); 161 r = m.count(9); 162 assert(r == 1); 163 r = m.count(10); 164 assert(r == 1); 165 r = m.count(11); 166 assert(r == 1); 167 r = m.count(12); 168 assert(r == 1); 169 r = m.count(4); 170 assert(r == 0); 171 } 172 #endif 173 } 174