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