llvm-project
119 строк · 3.5 Кб
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// <set>
12
13// class multiset
14
15// multiset(multiset&& s);
16
17#include <set>
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{
27{
28typedef int V;
29typedef test_less<int> C;
30typedef test_allocator<V> A;
31std::multiset<int, C, A> mo(C(5), A(7));
32std::multiset<int, 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{
44typedef int V;
45V ar[] =
46{
471,
481,
491,
502,
512,
522,
533,
543,
553
56};
57typedef test_less<int> C;
58typedef test_allocator<V> A;
59std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
60std::multiset<int, C, A> m = std::move(mo);
61assert(m.get_allocator() == A(7));
62assert(m.key_comp() == C(5));
63assert(m.size() == 9);
64assert(std::distance(m.begin(), m.end()) == 9);
65assert(*std::next(m.begin(), 0) == 1);
66assert(*std::next(m.begin(), 1) == 1);
67assert(*std::next(m.begin(), 2) == 1);
68assert(*std::next(m.begin(), 3) == 2);
69assert(*std::next(m.begin(), 4) == 2);
70assert(*std::next(m.begin(), 5) == 2);
71assert(*std::next(m.begin(), 6) == 3);
72assert(*std::next(m.begin(), 7) == 3);
73assert(*std::next(m.begin(), 8) == 3);
74
75assert(mo.get_allocator() == A(test_alloc_base::moved_value));
76assert(mo.key_comp() == C(5));
77assert(mo.size() == 0);
78assert(std::distance(mo.begin(), mo.end()) == 0);
79}
80{
81typedef int V;
82V ar[] =
83{
841,
851,
861,
872,
882,
892,
903,
913,
923
93};
94typedef test_less<int> C;
95typedef min_allocator<V> A;
96std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
97std::multiset<int, C, A> m = std::move(mo);
98assert(m.get_allocator() == A());
99assert(m.key_comp() == C(5));
100assert(m.size() == 9);
101assert(std::distance(m.begin(), m.end()) == 9);
102assert(*std::next(m.begin(), 0) == 1);
103assert(*std::next(m.begin(), 1) == 1);
104assert(*std::next(m.begin(), 2) == 1);
105assert(*std::next(m.begin(), 3) == 2);
106assert(*std::next(m.begin(), 4) == 2);
107assert(*std::next(m.begin(), 5) == 2);
108assert(*std::next(m.begin(), 6) == 3);
109assert(*std::next(m.begin(), 7) == 3);
110assert(*std::next(m.begin(), 8) == 3);
111
112assert(mo.get_allocator() == A());
113assert(mo.key_comp() == C(5));
114assert(mo.size() == 0);
115assert(std::distance(mo.begin(), mo.end()) == 0);
116}
117
118return 0;
119}
120