xref: /llvm-project/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp (revision 432ba353d8fcd68721203e1d0eb1fb983485f568)
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 
25 int main(int, char**)
26 {
27     {
28         typedef int V;
29         typedef test_less<int> C;
30         typedef test_allocator<V> A;
31         std::set<int, C, A> mo(C(5), A(7));
32         std::set<int, 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(7));
39         assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
40         assert(mo.key_comp() == C(5));
41         assert(mo.size() == 0);
42         assert(std::distance(mo.begin(), mo.end()) == 0);
43     }
44     {
45         typedef int V;
46         V ar[] =
47         {
48             1,
49             1,
50             1,
51             2,
52             2,
53             2,
54             3,
55             3,
56             3
57         };
58         typedef test_less<int> C;
59         typedef test_allocator<V> A;
60         std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
61         std::set<int, C, A> m = std::move(mo);
62         assert(m.get_allocator() == A(7));
63         assert(m.key_comp() == C(5));
64         assert(m.size() == 3);
65         assert(std::distance(m.begin(), m.end()) == 3);
66         assert(*m.begin() == 1);
67         assert(*std::next(m.begin()) == 2);
68         assert(*std::next(m.begin(), 2) == 3);
69 
70         assert(mo.get_allocator() == A(7));
71         assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
72         assert(mo.key_comp() == C(5));
73         assert(mo.size() == 0);
74         assert(std::distance(mo.begin(), mo.end()) == 0);
75     }
76     {
77         typedef int V;
78         V ar[] =
79         {
80             1,
81             1,
82             1,
83             2,
84             2,
85             2,
86             3,
87             3,
88             3
89         };
90         typedef test_less<int> C;
91         typedef min_allocator<V> A;
92         std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
93         std::set<int, C, A> m = std::move(mo);
94         assert(m.get_allocator() == A());
95         assert(m.key_comp() == C(5));
96         assert(m.size() == 3);
97         assert(std::distance(m.begin(), m.end()) == 3);
98         assert(*m.begin() == 1);
99         assert(*std::next(m.begin()) == 2);
100         assert(*std::next(m.begin(), 2) == 3);
101 
102         assert(mo.get_allocator() == A());
103         assert(mo.key_comp() == C(5));
104         assert(mo.size() == 0);
105         assert(std::distance(mo.begin(), mo.end()) == 0);
106     }
107 
108   return 0;
109 }
110