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 // pair<iterator, bool> insert(value_type&& v);
15 
16 #include <set>
17 #include <cassert>
18 
19 #include "../../MoveOnly.h"
20 #include "../../min_allocator.h"
21 
22 int main()
23 {
24 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
25     {
26         typedef std::set<MoveOnly> M;
27         typedef std::pair<M::iterator, bool> R;
28         M m;
29         R r = m.insert(M::value_type(2));
30         assert(r.second);
31         assert(r.first == m.begin());
32         assert(m.size() == 1);
33         assert(*r.first == 2);
34 
35         r = m.insert(M::value_type(1));
36         assert(r.second);
37         assert(r.first == m.begin());
38         assert(m.size() == 2);
39         assert(*r.first == 1);
40 
41         r = m.insert(M::value_type(3));
42         assert(r.second);
43         assert(r.first == prev(m.end()));
44         assert(m.size() == 3);
45         assert(*r.first == 3);
46 
47         r = m.insert(M::value_type(3));
48         assert(!r.second);
49         assert(r.first == prev(m.end()));
50         assert(m.size() == 3);
51         assert(*r.first == 3);
52     }
53 #if __cplusplus >= 201103L
54     {
55         typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M;
56         typedef std::pair<M::iterator, bool> R;
57         M m;
58         R r = m.insert(M::value_type(2));
59         assert(r.second);
60         assert(r.first == m.begin());
61         assert(m.size() == 1);
62         assert(*r.first == 2);
63 
64         r = m.insert(M::value_type(1));
65         assert(r.second);
66         assert(r.first == m.begin());
67         assert(m.size() == 2);
68         assert(*r.first == 1);
69 
70         r = m.insert(M::value_type(3));
71         assert(r.second);
72         assert(r.first == prev(m.end()));
73         assert(m.size() == 3);
74         assert(*r.first == 3);
75 
76         r = m.insert(M::value_type(3));
77         assert(!r.second);
78         assert(r.first == prev(m.end()));
79         assert(m.size() == 3);
80         assert(*r.first == 3);
81     }
82 #endif
83 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
84 }
85