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