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 // const key_compare& comp, const allocator_type& a); 17 18 #include <map> 19 #include <cassert> 20 21 #include "../../../test_compare.h" 22 #include "test_allocator.h" 23 #include "min_allocator.h" 24 25 int main() 26 { 27 { 28 typedef std::pair<const int, double> V; 29 V ar[] = 30 { 31 V(1, 1), 32 V(1, 1.5), 33 V(1, 2), 34 V(2, 1), 35 V(2, 1.5), 36 V(2, 2), 37 V(3, 1), 38 V(3, 1.5), 39 V(3, 2), 40 }; 41 typedef test_compare<std::less<int> > C; 42 typedef test_allocator<V> A; 43 std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); 44 assert(m.get_allocator() == A(7)); 45 assert(m.key_comp() == C(5)); 46 assert(m.size() == 9); 47 assert(distance(m.begin(), m.end()) == 9); 48 assert(*m.begin() == V(1, 1)); 49 assert(*next(m.begin()) == V(1, 1.5)); 50 assert(*next(m.begin(), 2) == V(1, 2)); 51 assert(*next(m.begin(), 3) == V(2, 1)); 52 assert(*next(m.begin(), 4) == V(2, 1.5)); 53 assert(*next(m.begin(), 5) == V(2, 2)); 54 assert(*next(m.begin(), 6) == V(3, 1)); 55 assert(*next(m.begin(), 7) == V(3, 1.5)); 56 assert(*next(m.begin(), 8) == V(3, 2)); 57 } 58 #if TEST_STD_VER >= 11 59 { 60 typedef std::pair<const int, double> V; 61 V ar[] = 62 { 63 V(1, 1), 64 V(1, 1.5), 65 V(1, 2), 66 V(2, 1), 67 V(2, 1.5), 68 V(2, 2), 69 V(3, 1), 70 V(3, 1.5), 71 V(3, 2), 72 }; 73 typedef test_compare<std::less<int> > C; 74 typedef min_allocator<V> A; 75 std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); 76 assert(m.get_allocator() == A()); 77 assert(m.key_comp() == C(5)); 78 assert(m.size() == 9); 79 assert(distance(m.begin(), m.end()) == 9); 80 assert(*m.begin() == V(1, 1)); 81 assert(*next(m.begin()) == V(1, 1.5)); 82 assert(*next(m.begin(), 2) == V(1, 2)); 83 assert(*next(m.begin(), 3) == V(2, 1)); 84 assert(*next(m.begin(), 4) == V(2, 1.5)); 85 assert(*next(m.begin(), 5) == V(2, 2)); 86 assert(*next(m.begin(), 6) == V(3, 1)); 87 assert(*next(m.begin(), 7) == V(3, 1.5)); 88 assert(*next(m.begin(), 8) == V(3, 2)); 89 } 90 { 91 typedef std::pair<const int, double> V; 92 V ar[] = 93 { 94 V(1, 1), 95 V(1, 1.5), 96 V(1, 2), 97 V(2, 1), 98 V(2, 1.5), 99 V(2, 2), 100 V(3, 1), 101 V(3, 1.5), 102 V(3, 2), 103 }; 104 typedef test_compare<std::less<int> > C; 105 typedef explicit_allocator<V> A; 106 std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A{}); 107 assert(m.get_allocator() == A{}); 108 assert(m.key_comp() == C(5)); 109 assert(m.size() == 9); 110 assert(distance(m.begin(), m.end()) == 9); 111 assert(*m.begin() == V(1, 1)); 112 assert(*next(m.begin()) == V(1, 1.5)); 113 assert(*next(m.begin(), 2) == V(1, 2)); 114 assert(*next(m.begin(), 3) == V(2, 1)); 115 assert(*next(m.begin(), 4) == V(2, 1.5)); 116 assert(*next(m.begin(), 5) == V(2, 2)); 117 assert(*next(m.begin(), 6) == V(3, 1)); 118 assert(*next(m.begin(), 7) == V(3, 1.5)); 119 assert(*next(m.begin(), 8) == V(3, 2)); 120 } 121 #endif 122 } 123