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