1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++03 10 11 // <map> 12 13 // class map 14 15 // map(map&& m); 16 17 #include <map> 18 #include <cassert> 19 20 #include "test_macros.h" 21 #include "../../../test_compare.h" 22 #include "test_allocator.h" 23 #include "min_allocator.h" 24 25 int main(int, char**) 26 { 27 typedef std::pair<const int, double> V; 28 { 29 typedef test_less<int> C; 30 typedef test_allocator<V> A; 31 std::map<int, double, C, A> mo(C(5), A(7)); 32 std::map<int, double, C, A> m = std::move(mo); 33 assert(m.get_allocator() == A(7)); 34 assert(m.key_comp() == C(5)); 35 assert(m.size() == 0); 36 assert(std::distance(m.begin(), m.end()) == 0); 37 38 assert(mo.get_allocator() == A(7)); 39 assert(mo.get_allocator().get_id() == test_alloc_base::moved_value); 40 assert(mo.key_comp() == C(5)); 41 assert(mo.size() == 0); 42 assert(std::distance(mo.begin(), mo.end()) == 0); 43 } 44 { 45 V ar[] = 46 { 47 V(1, 1), 48 V(1, 1.5), 49 V(1, 2), 50 V(2, 1), 51 V(2, 1.5), 52 V(2, 2), 53 V(3, 1), 54 V(3, 1.5), 55 V(3, 2), 56 }; 57 typedef test_less<int> C; 58 typedef test_allocator<V> A; 59 std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); 60 std::map<int, double, C, A> m = std::move(mo); 61 assert(m.get_allocator() == A(7)); 62 assert(m.key_comp() == C(5)); 63 assert(m.size() == 3); 64 assert(std::distance(m.begin(), m.end()) == 3); 65 assert(*m.begin() == V(1, 1)); 66 assert(*std::next(m.begin()) == V(2, 1)); 67 assert(*std::next(m.begin(), 2) == V(3, 1)); 68 69 assert(mo.get_allocator() == A(7)); 70 assert(mo.get_allocator().get_id() == test_alloc_base::moved_value); 71 assert(mo.key_comp() == C(5)); 72 assert(mo.size() == 0); 73 assert(std::distance(mo.begin(), mo.end()) == 0); 74 } 75 { 76 typedef test_less<int> C; 77 typedef min_allocator<V> A; 78 std::map<int, double, C, A> mo(C(5), A()); 79 std::map<int, double, C, A> m = std::move(mo); 80 assert(m.get_allocator() == A()); 81 assert(m.key_comp() == C(5)); 82 assert(m.size() == 0); 83 assert(std::distance(m.begin(), m.end()) == 0); 84 85 assert(mo.get_allocator() == A()); 86 assert(mo.key_comp() == C(5)); 87 assert(mo.size() == 0); 88 assert(std::distance(mo.begin(), mo.end()) == 0); 89 } 90 { 91 V ar[] = 92 { 93 V(1, 1), 94 V(1, 1.5), 95 V(1, 2), 96 V(2, 1), 97 V(2, 1.5), 98 V(2, 2), 99 V(3, 1), 100 V(3, 1.5), 101 V(3, 2), 102 }; 103 typedef test_less<int> C; 104 typedef min_allocator<V> A; 105 std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); 106 std::map<int, double, C, A> m = std::move(mo); 107 assert(m.get_allocator() == A()); 108 assert(m.key_comp() == C(5)); 109 assert(m.size() == 3); 110 assert(std::distance(m.begin(), m.end()) == 3); 111 assert(*m.begin() == V(1, 1)); 112 assert(*std::next(m.begin()) == V(2, 1)); 113 assert(*std::next(m.begin(), 2) == V(3, 1)); 114 115 assert(mo.get_allocator() == A()); 116 assert(mo.key_comp() == C(5)); 117 assert(mo.size() == 0); 118 assert(std::distance(mo.begin(), mo.end()) == 0); 119 } 120 121 return 0; 122 } 123