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