llvm-project
107 строк · 2.9 Кб
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 set
14
15// set(set&& 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::set<int, C, A> mo(C(5), A(7));
32std::set<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::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
60std::set<int, C, A> m = std::move(mo);
61assert(m.get_allocator() == A(7));
62assert(m.key_comp() == C(5));
63assert(m.size() == 3);
64assert(std::distance(m.begin(), m.end()) == 3);
65assert(*m.begin() == 1);
66assert(*std::next(m.begin()) == 2);
67assert(*std::next(m.begin(), 2) == 3);
68
69assert(mo.get_allocator() == A(test_alloc_base::moved_value));
70assert(mo.key_comp() == C(5));
71assert(mo.size() == 0);
72assert(std::distance(mo.begin(), mo.end()) == 0);
73}
74{
75typedef int V;
76V ar[] =
77{
781,
791,
801,
812,
822,
832,
843,
853,
863
87};
88typedef test_less<int> C;
89typedef min_allocator<V> A;
90std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
91std::set<int, C, A> m = std::move(mo);
92assert(m.get_allocator() == A());
93assert(m.key_comp() == C(5));
94assert(m.size() == 3);
95assert(std::distance(m.begin(), m.end()) == 3);
96assert(*m.begin() == 1);
97assert(*std::next(m.begin()) == 2);
98assert(*std::next(m.begin(), 2) == 3);
99
100assert(mo.get_allocator() == A());
101assert(mo.key_comp() == C(5));
102assert(mo.size() == 0);
103assert(std::distance(mo.begin(), mo.end()) == 0);
104}
105
106return 0;
107}
108