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 find(const key_type& k); 15 // const_iterator find(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.find(5); 40 assert(r == m.begin()); 41 r = m.find(6); 42 assert(r == m.end()); 43 r = m.find(7); 44 assert(r == next(m.begin(), 3)); 45 r = m.find(8); 46 assert(r == m.end()); 47 r = m.find(9); 48 assert(r == next(m.begin(), 6)); 49 r = m.find(10); 50 assert(r == m.end()); 51 } 52 { 53 typedef M::const_iterator R; 54 V ar[] = 55 { 56 V(5, 1), 57 V(5, 2), 58 V(5, 3), 59 V(7, 1), 60 V(7, 2), 61 V(7, 3), 62 V(9, 1), 63 V(9, 2), 64 V(9, 3) 65 }; 66 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 67 R r = m.find(5); 68 assert(r == m.begin()); 69 r = m.find(6); 70 assert(r == m.end()); 71 r = m.find(7); 72 assert(r == next(m.begin(), 3)); 73 r = m.find(8); 74 assert(r == m.end()); 75 r = m.find(9); 76 assert(r == next(m.begin(), 6)); 77 r = m.find(10); 78 assert(r == m.end()); 79 } 80 } 81