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 // iterator upper_bound(const key_type& k); 15 // const_iterator upper_bound(const key_type& k) const; 16 17 #include <map> 18 #include <cassert> 19 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::iterator 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 M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 44 R r = m.upper_bound(4); 45 assert(r == m.begin()); 46 r = m.upper_bound(5); 47 assert(r == next(m.begin(), 3)); 48 r = m.upper_bound(6); 49 assert(r == next(m.begin(), 3)); 50 r = m.upper_bound(7); 51 assert(r == next(m.begin(), 6)); 52 r = m.upper_bound(8); 53 assert(r == next(m.begin(), 6)); 54 r = m.upper_bound(9); 55 assert(r == next(m.begin(), 9)); 56 r = m.upper_bound(10); 57 assert(r == m.end()); 58 } 59 { 60 typedef M::const_iterator R; 61 V ar[] = 62 { 63 V(5, 1), 64 V(5, 2), 65 V(5, 3), 66 V(7, 1), 67 V(7, 2), 68 V(7, 3), 69 V(9, 1), 70 V(9, 2), 71 V(9, 3) 72 }; 73 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 74 R r = m.upper_bound(4); 75 assert(r == m.begin()); 76 r = m.upper_bound(5); 77 assert(r == next(m.begin(), 3)); 78 r = m.upper_bound(6); 79 assert(r == next(m.begin(), 3)); 80 r = m.upper_bound(7); 81 assert(r == next(m.begin(), 6)); 82 r = m.upper_bound(8); 83 assert(r == next(m.begin(), 6)); 84 r = m.upper_bound(9); 85 assert(r == next(m.begin(), 9)); 86 r = m.upper_bound(10); 87 assert(r == m.end()); 88 } 89 } 90 #if __cplusplus >= 201103L 91 { 92 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; 93 { 94 typedef M::iterator R; 95 V ar[] = 96 { 97 V(5, 1), 98 V(5, 2), 99 V(5, 3), 100 V(7, 1), 101 V(7, 2), 102 V(7, 3), 103 V(9, 1), 104 V(9, 2), 105 V(9, 3) 106 }; 107 M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 108 R r = m.upper_bound(4); 109 assert(r == m.begin()); 110 r = m.upper_bound(5); 111 assert(r == next(m.begin(), 3)); 112 r = m.upper_bound(6); 113 assert(r == next(m.begin(), 3)); 114 r = m.upper_bound(7); 115 assert(r == next(m.begin(), 6)); 116 r = m.upper_bound(8); 117 assert(r == next(m.begin(), 6)); 118 r = m.upper_bound(9); 119 assert(r == next(m.begin(), 9)); 120 r = m.upper_bound(10); 121 assert(r == m.end()); 122 } 123 { 124 typedef M::const_iterator R; 125 V ar[] = 126 { 127 V(5, 1), 128 V(5, 2), 129 V(5, 3), 130 V(7, 1), 131 V(7, 2), 132 V(7, 3), 133 V(9, 1), 134 V(9, 2), 135 V(9, 3) 136 }; 137 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 138 R r = m.upper_bound(4); 139 assert(r == m.begin()); 140 r = m.upper_bound(5); 141 assert(r == next(m.begin(), 3)); 142 r = m.upper_bound(6); 143 assert(r == next(m.begin(), 3)); 144 r = m.upper_bound(7); 145 assert(r == next(m.begin(), 6)); 146 r = m.upper_bound(8); 147 assert(r == next(m.begin(), 6)); 148 r = m.upper_bound(9); 149 assert(r == next(m.begin(), 9)); 150 r = m.upper_bound(10); 151 assert(r == m.end()); 152 } 153 } 154 #endif 155 #if _LIBCPP_STD_VER > 11 156 { 157 typedef std::pair<const int, double> V; 158 typedef std::multimap<int, double, std::less<>> M; 159 typedef M::iterator R; 160 V ar[] = 161 { 162 V(5, 1), 163 V(5, 2), 164 V(5, 3), 165 V(7, 1), 166 V(7, 2), 167 V(7, 3), 168 V(9, 1), 169 V(9, 2), 170 V(9, 3) 171 }; 172 M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 173 R r = m.upper_bound(4); 174 assert(r == m.begin()); 175 r = m.upper_bound(5); 176 assert(r == next(m.begin(), 3)); 177 r = m.upper_bound(6); 178 assert(r == next(m.begin(), 3)); 179 r = m.upper_bound(7); 180 assert(r == next(m.begin(), 6)); 181 r = m.upper_bound(8); 182 assert(r == next(m.begin(), 6)); 183 r = m.upper_bound(9); 184 assert(r == next(m.begin(), 9)); 185 r = m.upper_bound(10); 186 assert(r == m.end()); 187 188 r = m.upper_bound(C2Int(4)); 189 assert(r == m.begin()); 190 r = m.upper_bound(C2Int(5)); 191 assert(r == next(m.begin(), 3)); 192 r = m.upper_bound(C2Int(6)); 193 assert(r == next(m.begin(), 3)); 194 r = m.upper_bound(C2Int(7)); 195 assert(r == next(m.begin(), 6)); 196 r = m.upper_bound(C2Int(8)); 197 assert(r == next(m.begin(), 6)); 198 r = m.upper_bound(C2Int(9)); 199 assert(r == next(m.begin(), 9)); 200 r = m.upper_bound(C2Int(10)); 201 } 202 203 { 204 typedef PrivateConstructor PC; 205 typedef std::multimap<PC, double, std::less<>> M; 206 typedef M::iterator R; 207 208 M m; 209 m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 )); 210 m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 )); 211 m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 )); 212 m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 )); 213 m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 )); 214 m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 )); 215 m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 )); 216 m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 )); 217 m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 )); 218 219 R r = m.upper_bound(4); 220 assert(r == m.begin()); 221 r = m.upper_bound(5); 222 assert(r == next(m.begin(), 3)); 223 r = m.upper_bound(6); 224 assert(r == next(m.begin(), 3)); 225 r = m.upper_bound(7); 226 assert(r == next(m.begin(), 6)); 227 r = m.upper_bound(8); 228 assert(r == next(m.begin(), 6)); 229 r = m.upper_bound(9); 230 assert(r == next(m.begin(), 9)); 231 r = m.upper_bound(10); 232 assert(r == m.end()); 233 } 234 235 #endif 236 } 237