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