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 map 13 14 // map& operator=(const map& m); 15 16 #include <map> 17 #include <cassert> 18 19 #include "../../../test_compare.h" 20 #include "test_allocator.h" 21 #include "min_allocator.h" 22 23 int main() 24 { 25 { 26 typedef std::pair<const int, double> V; 27 V ar[] = 28 { 29 V(1, 1), 30 V(1, 1.5), 31 V(1, 2), 32 V(2, 1), 33 V(2, 1.5), 34 V(2, 2), 35 V(3, 1), 36 V(3, 1.5), 37 V(3, 2) 38 }; 39 typedef test_compare<std::less<int> > C; 40 typedef test_allocator<V> A; 41 std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); 42 std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); 43 m = mo; 44 assert(m.get_allocator() == A(7)); 45 assert(m.key_comp() == C(5)); 46 assert(m.size() == 3); 47 assert(distance(m.begin(), m.end()) == 3); 48 assert(*m.begin() == V(1, 1)); 49 assert(*next(m.begin()) == V(2, 1)); 50 assert(*next(m.begin(), 2) == V(3, 1)); 51 52 assert(mo.get_allocator() == A(2)); 53 assert(mo.key_comp() == C(5)); 54 assert(mo.size() == 3); 55 assert(distance(mo.begin(), mo.end()) == 3); 56 assert(*mo.begin() == V(1, 1)); 57 assert(*next(mo.begin()) == V(2, 1)); 58 assert(*next(mo.begin(), 2) == V(3, 1)); 59 } 60 { 61 typedef std::pair<const int, double> V; 62 const V ar[] = 63 { 64 V(1, 1), 65 V(2, 1), 66 V(3, 1), 67 }; 68 std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 69 std::map<int, double> *p = &m; 70 m = *p; 71 72 assert(m.size() == 3); 73 assert(std::equal(m.begin(), m.end(), ar)); 74 } 75 { 76 typedef std::pair<const int, double> V; 77 V ar[] = 78 { 79 V(1, 1), 80 V(1, 1.5), 81 V(1, 2), 82 V(2, 1), 83 V(2, 1.5), 84 V(2, 2), 85 V(3, 1), 86 V(3, 1.5), 87 V(3, 2) 88 }; 89 typedef test_compare<std::less<int> > C; 90 typedef other_allocator<V> A; 91 std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); 92 std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); 93 m = mo; 94 assert(m.get_allocator() == A(2)); 95 assert(m.key_comp() == C(5)); 96 assert(m.size() == 3); 97 assert(distance(m.begin(), m.end()) == 3); 98 assert(*m.begin() == V(1, 1)); 99 assert(*next(m.begin()) == V(2, 1)); 100 assert(*next(m.begin(), 2) == V(3, 1)); 101 102 assert(mo.get_allocator() == A(2)); 103 assert(mo.key_comp() == C(5)); 104 assert(mo.size() == 3); 105 assert(distance(mo.begin(), mo.end()) == 3); 106 assert(*mo.begin() == V(1, 1)); 107 assert(*next(mo.begin()) == V(2, 1)); 108 assert(*next(mo.begin(), 2) == V(3, 1)); 109 } 110 #if __cplusplus >= 201103L 111 { 112 typedef std::pair<const int, double> V; 113 V ar[] = 114 { 115 V(1, 1), 116 V(1, 1.5), 117 V(1, 2), 118 V(2, 1), 119 V(2, 1.5), 120 V(2, 2), 121 V(3, 1), 122 V(3, 1.5), 123 V(3, 2) 124 }; 125 typedef test_compare<std::less<int> > C; 126 typedef min_allocator<V> A; 127 std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); 128 std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); 129 m = mo; 130 assert(m.get_allocator() == A()); 131 assert(m.key_comp() == C(5)); 132 assert(m.size() == 3); 133 assert(distance(m.begin(), m.end()) == 3); 134 assert(*m.begin() == V(1, 1)); 135 assert(*next(m.begin()) == V(2, 1)); 136 assert(*next(m.begin(), 2) == V(3, 1)); 137 138 assert(mo.get_allocator() == A()); 139 assert(mo.key_comp() == C(5)); 140 assert(mo.size() == 3); 141 assert(distance(mo.begin(), mo.end()) == 3); 142 assert(*mo.begin() == V(1, 1)); 143 assert(*next(mo.begin()) == V(2, 1)); 144 assert(*next(mo.begin(), 2) == V(3, 1)); 145 } 146 { 147 typedef std::pair<const int, double> V; 148 V ar[] = 149 { 150 V(1, 1), 151 V(1, 1.5), 152 V(1, 2), 153 V(2, 1), 154 V(2, 1.5), 155 V(2, 2), 156 V(3, 1), 157 V(3, 1.5), 158 V(3, 2) 159 }; 160 typedef test_compare<std::less<int> > C; 161 typedef min_allocator<V> A; 162 std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); 163 std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); 164 m = mo; 165 assert(m.get_allocator() == A()); 166 assert(m.key_comp() == C(5)); 167 assert(m.size() == 3); 168 assert(distance(m.begin(), m.end()) == 3); 169 assert(*m.begin() == V(1, 1)); 170 assert(*next(m.begin()) == V(2, 1)); 171 assert(*next(m.begin(), 2) == V(3, 1)); 172 173 assert(mo.get_allocator() == A()); 174 assert(mo.key_comp() == C(5)); 175 assert(mo.size() == 3); 176 assert(distance(mo.begin(), mo.end()) == 3); 177 assert(*mo.begin() == V(1, 1)); 178 assert(*next(mo.begin()) == V(2, 1)); 179 assert(*next(mo.begin(), 2) == V(3, 1)); 180 } 181 #endif 182 } 183