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