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 multimap 14 15 // multimap(multimap&& 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::multimap<int, double, C, A> mo(C(5), A(7)); 32 std::multimap<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::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); 60 std::multimap<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() == 9); 64 assert(std::distance(m.begin(), m.end()) == 9); 65 assert(*m.begin() == V(1, 1)); 66 assert(*std::next(m.begin()) == V(1, 1.5)); 67 assert(*std::next(m.begin(), 2) == V(1, 2)); 68 assert(*std::next(m.begin(), 3) == V(2, 1)); 69 assert(*std::next(m.begin(), 4) == V(2, 1.5)); 70 assert(*std::next(m.begin(), 5) == V(2, 2)); 71 assert(*std::next(m.begin(), 6) == V(3, 1)); 72 assert(*std::next(m.begin(), 7) == V(3, 1.5)); 73 assert(*std::next(m.begin(), 8) == V(3, 2)); 74 75 assert(mo.get_allocator() == A(7)); 76 assert(mo.get_allocator().get_id() == test_alloc_base::moved_value); 77 assert(mo.key_comp() == C(5)); 78 assert(mo.size() == 0); 79 assert(std::distance(mo.begin(), mo.end()) == 0); 80 } 81 { 82 typedef test_less<int> C; 83 typedef min_allocator<V> A; 84 std::multimap<int, double, C, A> mo(C(5), A()); 85 std::multimap<int, double, C, A> m = std::move(mo); 86 assert(m.get_allocator() == A()); 87 assert(m.key_comp() == C(5)); 88 assert(m.size() == 0); 89 assert(std::distance(m.begin(), m.end()) == 0); 90 91 assert(mo.get_allocator() == A()); 92 assert(mo.key_comp() == C(5)); 93 assert(mo.size() == 0); 94 assert(std::distance(mo.begin(), mo.end()) == 0); 95 } 96 { 97 V ar[] = 98 { 99 V(1, 1), 100 V(1, 1.5), 101 V(1, 2), 102 V(2, 1), 103 V(2, 1.5), 104 V(2, 2), 105 V(3, 1), 106 V(3, 1.5), 107 V(3, 2), 108 }; 109 typedef test_less<int> C; 110 typedef min_allocator<V> A; 111 std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); 112 std::multimap<int, double, C, A> m = std::move(mo); 113 assert(m.get_allocator() == A()); 114 assert(m.key_comp() == C(5)); 115 assert(m.size() == 9); 116 assert(std::distance(m.begin(), m.end()) == 9); 117 assert(*m.begin() == V(1, 1)); 118 assert(*std::next(m.begin()) == V(1, 1.5)); 119 assert(*std::next(m.begin(), 2) == V(1, 2)); 120 assert(*std::next(m.begin(), 3) == V(2, 1)); 121 assert(*std::next(m.begin(), 4) == V(2, 1.5)); 122 assert(*std::next(m.begin(), 5) == V(2, 2)); 123 assert(*std::next(m.begin(), 6) == V(3, 1)); 124 assert(*std::next(m.begin(), 7) == V(3, 1.5)); 125 assert(*std::next(m.begin(), 8) == V(3, 2)); 126 127 assert(mo.get_allocator() == A()); 128 assert(mo.key_comp() == C(5)); 129 assert(mo.size() == 0); 130 assert(std::distance(mo.begin(), mo.end()) == 0); 131 } 132 133 return 0; 134 } 135