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 // template <class InputIterator> 15 // multimap(InputIterator first, InputIterator last); 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 V ar[] = 27 { 28 V(1, 1), 29 V(1, 1.5), 30 V(1, 2), 31 V(2, 1), 32 V(2, 1.5), 33 V(2, 2), 34 V(3, 1), 35 V(3, 1.5), 36 V(3, 2), 37 }; 38 std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 39 assert(m.size() == 9); 40 assert(distance(m.begin(), m.end()) == 9); 41 assert(*m.begin() == V(1, 1)); 42 assert(*next(m.begin()) == V(1, 1.5)); 43 assert(*next(m.begin(), 2) == V(1, 2)); 44 assert(*next(m.begin(), 3) == V(2, 1)); 45 assert(*next(m.begin(), 4) == V(2, 1.5)); 46 assert(*next(m.begin(), 5) == V(2, 2)); 47 assert(*next(m.begin(), 6) == V(3, 1)); 48 assert(*next(m.begin(), 7) == V(3, 1.5)); 49 assert(*next(m.begin(), 8) == V(3, 2)); 50 } 51 #if __cplusplus >= 201103L 52 { 53 typedef std::pair<const int, double> V; 54 V ar[] = 55 { 56 V(1, 1), 57 V(1, 1.5), 58 V(1, 2), 59 V(2, 1), 60 V(2, 1.5), 61 V(2, 2), 62 V(3, 1), 63 V(3, 1.5), 64 V(3, 2), 65 }; 66 std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 67 assert(m.size() == 9); 68 assert(distance(m.begin(), m.end()) == 9); 69 assert(*m.begin() == V(1, 1)); 70 assert(*next(m.begin()) == V(1, 1.5)); 71 assert(*next(m.begin(), 2) == V(1, 2)); 72 assert(*next(m.begin(), 3) == V(2, 1)); 73 assert(*next(m.begin(), 4) == V(2, 1.5)); 74 assert(*next(m.begin(), 5) == V(2, 2)); 75 assert(*next(m.begin(), 6) == V(3, 1)); 76 assert(*next(m.begin(), 7) == V(3, 1.5)); 77 assert(*next(m.begin(), 8) == V(3, 2)); 78 } 79 #if _LIBCPP_STD_VER > 11 80 { 81 typedef std::pair<const int, double> V; 82 V ar[] = 83 { 84 V(1, 1), 85 V(1, 1.5), 86 V(1, 2), 87 V(2, 1), 88 V(2, 1.5), 89 V(2, 2), 90 V(3, 1), 91 V(3, 1.5), 92 V(3, 2), 93 }; 94 typedef min_allocator<std::pair<const int, double>> A; 95 A a; 96 std::multimap<int, double, std::less<int>, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); 97 assert(m.size() == 9); 98 assert(distance(m.begin(), m.end()) == 9); 99 assert(*m.begin() == V(1, 1)); 100 assert(*next(m.begin()) == V(1, 1.5)); 101 assert(*next(m.begin(), 2) == V(1, 2)); 102 assert(*next(m.begin(), 3) == V(2, 1)); 103 assert(*next(m.begin(), 4) == V(2, 1.5)); 104 assert(*next(m.begin(), 5) == V(2, 2)); 105 assert(*next(m.begin(), 6) == V(3, 1)); 106 assert(*next(m.begin(), 7) == V(3, 1.5)); 107 assert(*next(m.begin(), 8) == V(3, 2)); 108 assert(m.get_allocator() == a); 109 } 110 #endif 111 #endif 112 } 113