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 typedef int V;
28 typedef test_less<int> C;
29 typedef test_allocator<V> A;
30 std::set<int, C, A> mo(C(5), A(7));
31 std::set<int, C, A> m = std::move(mo);
32 assert(m.get_allocator() == A(7));
33 assert(m.key_comp() == C(5));
34 assert(m.size() == 0);
35 assert(std::distance(m.begin(), m.end()) == 0);
36
37 assert(mo.get_allocator() == A(7));
38 assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
39 assert(mo.key_comp() == C(5));
40 assert(mo.size() == 0);
41 assert(std::distance(mo.begin(), mo.end()) == 0);
42 }
43 {
44 typedef int V;
45 V ar[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};
46 typedef test_less<int> C;
47 typedef test_allocator<V> A;
48 std::set<int, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(7));
49 std::set<int, C, A> m = std::move(mo);
50 assert(m.get_allocator() == A(7));
51 assert(m.key_comp() == C(5));
52 assert(m.size() == 3);
53 assert(std::distance(m.begin(), m.end()) == 3);
54 assert(*m.begin() == 1);
55 assert(*std::next(m.begin()) == 2);
56 assert(*std::next(m.begin(), 2) == 3);
57
58 assert(mo.get_allocator() == A(7));
59 assert(mo.get_allocator().get_id() == test_alloc_base::moved_value);
60 assert(mo.key_comp() == C(5));
61 assert(mo.size() == 0);
62 assert(std::distance(mo.begin(), mo.end()) == 0);
63 }
64 {
65 typedef int V;
66 V ar[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};
67 typedef test_less<int> C;
68 typedef min_allocator<V> A;
69 std::set<int, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A());
70 std::set<int, C, A> m = std::move(mo);
71 assert(m.get_allocator() == A());
72 assert(m.key_comp() == C(5));
73 assert(m.size() == 3);
74 assert(std::distance(m.begin(), m.end()) == 3);
75 assert(*m.begin() == 1);
76 assert(*std::next(m.begin()) == 2);
77 assert(*std::next(m.begin(), 2) == 3);
78
79 assert(mo.get_allocator() == A());
80 assert(mo.key_comp() == C(5));
81 assert(mo.size() == 0);
82 assert(std::distance(mo.begin(), mo.end()) == 0);
83 }
84
85 return 0;
86}
87

source code of libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp