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(map&& m, const allocator_type& a); 15 16 #include <map> 17 #include <cassert> 18 19 #include "../../../MoveOnly.h" 20 #include "../../../test_compare.h" 21 #include "../../../test_allocator.h" 22 23 int main() 24 { 25 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 26 { 27 typedef std::pair<MoveOnly, MoveOnly> V; 28 typedef std::pair<const MoveOnly, MoveOnly> VC; 29 typedef test_compare<std::less<MoveOnly> > C; 30 typedef test_allocator<VC> A; 31 typedef std::map<MoveOnly, MoveOnly, C, A> M; 32 typedef std::move_iterator<V*> I; 33 V a1[] = 34 { 35 V(1, 1), 36 V(1, 2), 37 V(1, 3), 38 V(2, 1), 39 V(2, 2), 40 V(2, 3), 41 V(3, 1), 42 V(3, 2), 43 V(3, 3) 44 }; 45 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 46 V a2[] = 47 { 48 V(1, 1), 49 V(1, 2), 50 V(1, 3), 51 V(2, 1), 52 V(2, 2), 53 V(2, 3), 54 V(3, 1), 55 V(3, 2), 56 V(3, 3) 57 }; 58 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 59 M m3(std::move(m1), A(7)); 60 assert(m3 == m2); 61 assert(m3.get_allocator() == A(7)); 62 assert(m3.key_comp() == C(5)); 63 assert(m1.empty()); 64 } 65 { 66 typedef std::pair<MoveOnly, MoveOnly> V; 67 typedef std::pair<const MoveOnly, MoveOnly> VC; 68 typedef test_compare<std::less<MoveOnly> > C; 69 typedef test_allocator<VC> A; 70 typedef std::map<MoveOnly, MoveOnly, C, A> M; 71 typedef std::move_iterator<V*> I; 72 V a1[] = 73 { 74 V(1, 1), 75 V(1, 2), 76 V(1, 3), 77 V(2, 1), 78 V(2, 2), 79 V(2, 3), 80 V(3, 1), 81 V(3, 2), 82 V(3, 3) 83 }; 84 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 85 V a2[] = 86 { 87 V(1, 1), 88 V(1, 2), 89 V(1, 3), 90 V(2, 1), 91 V(2, 2), 92 V(2, 3), 93 V(3, 1), 94 V(3, 2), 95 V(3, 3) 96 }; 97 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 98 M m3(std::move(m1), A(5)); 99 assert(m3 == m2); 100 assert(m3.get_allocator() == A(5)); 101 assert(m3.key_comp() == C(5)); 102 assert(m1.empty()); 103 } 104 { 105 typedef std::pair<MoveOnly, MoveOnly> V; 106 typedef std::pair<const MoveOnly, MoveOnly> VC; 107 typedef test_compare<std::less<MoveOnly> > C; 108 typedef other_allocator<VC> A; 109 typedef std::map<MoveOnly, MoveOnly, C, A> M; 110 typedef std::move_iterator<V*> I; 111 V a1[] = 112 { 113 V(1, 1), 114 V(1, 2), 115 V(1, 3), 116 V(2, 1), 117 V(2, 2), 118 V(2, 3), 119 V(3, 1), 120 V(3, 2), 121 V(3, 3) 122 }; 123 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 124 V a2[] = 125 { 126 V(1, 1), 127 V(1, 2), 128 V(1, 3), 129 V(2, 1), 130 V(2, 2), 131 V(2, 3), 132 V(3, 1), 133 V(3, 2), 134 V(3, 3) 135 }; 136 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 137 M m3(std::move(m1), A(5)); 138 assert(m3 == m2); 139 assert(m3.get_allocator() == A(5)); 140 assert(m3.key_comp() == C(5)); 141 assert(m1.empty()); 142 } 143 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 144 } 145