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 lower_bound(const key_type& k); 15 // const_iterator lower_bound(const key_type& k) const; 16 17 #include <map> 18 #include <cassert> 19 20 int main() 21 { 22 typedef std::pair<const int, double> V; 23 typedef std::multimap<int, double> M; 24 { 25 typedef M::iterator R; 26 V ar[] = 27 { 28 V(5, 1), 29 V(5, 2), 30 V(5, 3), 31 V(7, 1), 32 V(7, 2), 33 V(7, 3), 34 V(9, 1), 35 V(9, 2), 36 V(9, 3) 37 }; 38 M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 39 R r = m.lower_bound(4); 40 assert(r == m.begin()); 41 r = m.lower_bound(5); 42 assert(r == m.begin()); 43 r = m.lower_bound(6); 44 assert(r == next(m.begin(), 3)); 45 r = m.lower_bound(7); 46 assert(r == next(m.begin(), 3)); 47 r = m.lower_bound(8); 48 assert(r == next(m.begin(), 6)); 49 r = m.lower_bound(9); 50 assert(r == next(m.begin(), 6)); 51 r = m.lower_bound(10); 52 assert(r == m.end()); 53 } 54 { 55 typedef M::const_iterator R; 56 V ar[] = 57 { 58 V(5, 1), 59 V(5, 2), 60 V(5, 3), 61 V(7, 1), 62 V(7, 2), 63 V(7, 3), 64 V(9, 1), 65 V(9, 2), 66 V(9, 3) 67 }; 68 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 69 R r = m.lower_bound(4); 70 assert(r == m.begin()); 71 r = m.lower_bound(5); 72 assert(r == m.begin()); 73 r = m.lower_bound(6); 74 assert(r == next(m.begin(), 3)); 75 r = m.lower_bound(7); 76 assert(r == next(m.begin(), 3)); 77 r = m.lower_bound(8); 78 assert(r == next(m.begin(), 6)); 79 r = m.lower_bound(9); 80 assert(r == next(m.begin(), 6)); 81 r = m.lower_bound(10); 82 assert(r == m.end()); 83 } 84 } 85