1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <set>
11 
12 // class set
13 
14 // set(set&& s);
15 
16 #include <set>
17 #include <cassert>
18 
19 #include "../../../test_compare.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22 
main()23 int main()
24 {
25 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
26     {
27         typedef int V;
28         typedef test_compare<std::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(distance(m.begin(), m.end()) == 0);
36 
37         assert(mo.get_allocator() == A(7));
38         assert(mo.key_comp() == C(5));
39         assert(mo.size() == 0);
40         assert(distance(mo.begin(), mo.end()) == 0);
41     }
42     {
43         typedef int V;
44         V ar[] =
45         {
46             1,
47             1,
48             1,
49             2,
50             2,
51             2,
52             3,
53             3,
54             3
55         };
56         typedef test_compare<std::less<int> > C;
57         typedef test_allocator<V> A;
58         std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
59         std::set<int, C, A> m = std::move(mo);
60         assert(m.get_allocator() == A(7));
61         assert(m.key_comp() == C(5));
62         assert(m.size() == 3);
63         assert(distance(m.begin(), m.end()) == 3);
64         assert(*m.begin() == 1);
65         assert(*next(m.begin()) == 2);
66         assert(*next(m.begin(), 2) == 3);
67 
68         assert(mo.get_allocator() == A(7));
69         assert(mo.key_comp() == C(5));
70         assert(mo.size() == 0);
71         assert(distance(mo.begin(), mo.end()) == 0);
72     }
73 #if __cplusplus >= 201103L
74     {
75         typedef int V;
76         V ar[] =
77         {
78             1,
79             1,
80             1,
81             2,
82             2,
83             2,
84             3,
85             3,
86             3
87         };
88         typedef test_compare<std::less<int> > C;
89         typedef min_allocator<V> A;
90         std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
91         std::set<int, C, A> m = std::move(mo);
92         assert(m.get_allocator() == A());
93         assert(m.key_comp() == C(5));
94         assert(m.size() == 3);
95         assert(distance(m.begin(), m.end()) == 3);
96         assert(*m.begin() == 1);
97         assert(*next(m.begin()) == 2);
98         assert(*next(m.begin(), 2) == 3);
99 
100         assert(mo.get_allocator() == A());
101         assert(mo.key_comp() == C(5));
102         assert(mo.size() == 0);
103         assert(distance(mo.begin(), mo.end()) == 0);
104     }
105 #endif
106 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
107 }
108