llvm-project
120 строк · 3.6 Кб
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
25int main(int, char**)
26{
27typedef std::pair<const int, double> V;
28{
29typedef test_less<int> C;
30typedef test_allocator<V> A;
31std::map<int, double, C, A> mo(C(5), A(7));
32std::map<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::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
59std::map<int, double, C, A> m = std::move(mo);
60assert(m.get_allocator() == A(7));
61assert(m.key_comp() == C(5));
62assert(m.size() == 3);
63assert(std::distance(m.begin(), m.end()) == 3);
64assert(*m.begin() == V(1, 1));
65assert(*std::next(m.begin()) == V(2, 1));
66assert(*std::next(m.begin(), 2) == V(3, 1));
67
68assert(mo.get_allocator() == A(test_alloc_base::moved_value));
69assert(mo.key_comp() == C(5));
70assert(mo.size() == 0);
71assert(std::distance(mo.begin(), mo.end()) == 0);
72}
73{
74typedef test_less<int> C;
75typedef min_allocator<V> A;
76std::map<int, double, C, A> mo(C(5), A());
77std::map<int, double, C, A> m = std::move(mo);
78assert(m.get_allocator() == A());
79assert(m.key_comp() == C(5));
80assert(m.size() == 0);
81assert(std::distance(m.begin(), m.end()) == 0);
82
83assert(mo.get_allocator() == A());
84assert(mo.key_comp() == C(5));
85assert(mo.size() == 0);
86assert(std::distance(mo.begin(), mo.end()) == 0);
87}
88{
89V ar[] =
90{
91V(1, 1),
92V(1, 1.5),
93V(1, 2),
94V(2, 1),
95V(2, 1.5),
96V(2, 2),
97V(3, 1),
98V(3, 1.5),
99V(3, 2),
100};
101typedef test_less<int> C;
102typedef min_allocator<V> A;
103std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
104std::map<int, double, C, A> m = std::move(mo);
105assert(m.get_allocator() == A());
106assert(m.key_comp() == C(5));
107assert(m.size() == 3);
108assert(std::distance(m.begin(), m.end()) == 3);
109assert(*m.begin() == V(1, 1));
110assert(*std::next(m.begin()) == V(2, 1));
111assert(*std::next(m.begin(), 2) == V(3, 1));
112
113assert(mo.get_allocator() == A());
114assert(mo.key_comp() == C(5));
115assert(mo.size() == 0);
116assert(std::distance(mo.begin(), mo.end()) == 0);
117}
118
119return 0;
120}
121