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++98, c++03
10 
11 // <set>
12 
13 // class set
14 
15 // pair<iterator, bool> insert(value_type&& v);
16 
17 #include <set>
18 #include <cassert>
19 
20 #include "MoveOnly.h"
21 #include "min_allocator.h"
22 
23 int main(int, char**)
24 {
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     {
54         typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M;
55         typedef std::pair<M::iterator, bool> R;
56         M m;
57         R r = m.insert(M::value_type(2));
58         assert(r.second);
59         assert(r.first == m.begin());
60         assert(m.size() == 1);
61         assert(*r.first == 2);
62 
63         r = m.insert(M::value_type(1));
64         assert(r.second);
65         assert(r.first == m.begin());
66         assert(m.size() == 2);
67         assert(*r.first == 1);
68 
69         r = m.insert(M::value_type(3));
70         assert(r.second);
71         assert(r.first == prev(m.end()));
72         assert(m.size() == 3);
73         assert(*r.first == 3);
74 
75         r = m.insert(M::value_type(3));
76         assert(!r.second);
77         assert(r.first == prev(m.end()));
78         assert(m.size() == 3);
79         assert(*r.first == 3);
80     }
81 
82   return 0;
83 }
84