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 #include "is_transparent.h" 22 23 int main() 24 { 25 { 26 typedef std::pair<const int, double> V; 27 typedef std::map<int, double> M; 28 { 29 typedef M::size_type R; 30 V ar[] = 31 { 32 V(5, 5), 33 V(6, 6), 34 V(7, 7), 35 V(8, 8), 36 V(9, 9), 37 V(10, 10), 38 V(11, 11), 39 V(12, 12) 40 }; 41 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 42 R r = m.count(5); 43 assert(r == 1); 44 r = m.count(6); 45 assert(r == 1); 46 r = m.count(7); 47 assert(r == 1); 48 r = m.count(8); 49 assert(r == 1); 50 r = m.count(9); 51 assert(r == 1); 52 r = m.count(10); 53 assert(r == 1); 54 r = m.count(11); 55 assert(r == 1); 56 r = m.count(12); 57 assert(r == 1); 58 r = m.count(4); 59 assert(r == 0); 60 } 61 } 62 #if __cplusplus >= 201103L 63 { 64 typedef std::pair<const int, double> V; 65 typedef std::map<int, double, std::less<int>, min_allocator<V>> M; 66 { 67 typedef M::size_type R; 68 V ar[] = 69 { 70 V(5, 5), 71 V(6, 6), 72 V(7, 7), 73 V(8, 8), 74 V(9, 9), 75 V(10, 10), 76 V(11, 11), 77 V(12, 12) 78 }; 79 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 80 R r = m.count(5); 81 assert(r == 1); 82 r = m.count(6); 83 assert(r == 1); 84 r = m.count(7); 85 assert(r == 1); 86 r = m.count(8); 87 assert(r == 1); 88 r = m.count(9); 89 assert(r == 1); 90 r = m.count(10); 91 assert(r == 1); 92 r = m.count(11); 93 assert(r == 1); 94 r = m.count(12); 95 assert(r == 1); 96 r = m.count(4); 97 assert(r == 0); 98 } 99 } 100 #endif 101 #if _LIBCPP_STD_VER > 11 102 { 103 typedef std::pair<const int, double> V; 104 typedef std::map<int, double, std::less <>> M; 105 typedef M::size_type R; 106 107 V ar[] = 108 { 109 V(5, 5), 110 V(6, 6), 111 V(7, 7), 112 V(8, 8), 113 V(9, 9), 114 V(10, 10), 115 V(11, 11), 116 V(12, 12) 117 }; 118 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 119 R r = m.count(5); 120 assert(r == 1); 121 r = m.count(6); 122 assert(r == 1); 123 r = m.count(7); 124 assert(r == 1); 125 r = m.count(8); 126 assert(r == 1); 127 r = m.count(9); 128 assert(r == 1); 129 r = m.count(10); 130 assert(r == 1); 131 r = m.count(11); 132 assert(r == 1); 133 r = m.count(12); 134 assert(r == 1); 135 r = m.count(4); 136 assert(r == 0); 137 138 r = m.count(C2Int(5)); 139 assert(r == 1); 140 r = m.count(C2Int(6)); 141 assert(r == 1); 142 r = m.count(C2Int(7)); 143 assert(r == 1); 144 r = m.count(C2Int(8)); 145 assert(r == 1); 146 r = m.count(C2Int(9)); 147 assert(r == 1); 148 r = m.count(C2Int(10)); 149 assert(r == 1); 150 r = m.count(C2Int(11)); 151 assert(r == 1); 152 r = m.count(C2Int(12)); 153 assert(r == 1); 154 r = m.count(C2Int(4)); 155 assert(r == 0); 156 } 157 158 { 159 typedef PrivateConstructor PC; 160 typedef std::map<PC, double, std::less<>> M; 161 typedef M::size_type R; 162 163 M m; 164 m [ PC::make(5) ] = 5; 165 m [ PC::make(6) ] = 6; 166 m [ PC::make(7) ] = 7; 167 m [ PC::make(8) ] = 8; 168 m [ PC::make(9) ] = 9; 169 m [ PC::make(10) ] = 10; 170 m [ PC::make(11) ] = 11; 171 m [ PC::make(12) ] = 12; 172 173 R r = m.count(5); 174 assert(r == 1); 175 r = m.count(6); 176 assert(r == 1); 177 r = m.count(7); 178 assert(r == 1); 179 r = m.count(8); 180 assert(r == 1); 181 r = m.count(9); 182 assert(r == 1); 183 r = m.count(10); 184 assert(r == 1); 185 r = m.count(11); 186 assert(r == 1); 187 r = m.count(12); 188 assert(r == 1); 189 r = m.count(4); 190 assert(r == 0); 191 } 192 #endif 193 } 194