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 // <unordered_set>
11 
12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13 //           class Alloc = allocator<Value>>
14 // class unordered_set
15 
16 // iterator insert(const_iterator p, value_type&& x);
17 
18 #if _LIBCPP_DEBUG >= 1
19 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
20 #endif
21 
22 #include <unordered_set>
23 #include <cassert>
24 
25 #include "MoveOnly.h"
26 #include "min_allocator.h"
27 
main()28 int main()
29 {
30     {
31         typedef std::unordered_set<double> C;
32         typedef C::iterator R;
33         typedef double P;
34         C c;
35         C::const_iterator e = c.end();
36         R r = c.insert(e, P(3.5));
37         assert(c.size() == 1);
38         assert(*r == 3.5);
39 
40         r = c.insert(r, P(3.5));
41         assert(c.size() == 1);
42         assert(*r == 3.5);
43 
44         r = c.insert(e, P(4.5));
45         assert(c.size() == 2);
46         assert(*r == 4.5);
47 
48         r = c.insert(e, P(5.5));
49         assert(c.size() == 3);
50         assert(*r == 5.5);
51     }
52 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
53     {
54         typedef std::unordered_set<MoveOnly> C;
55         typedef C::iterator R;
56         typedef MoveOnly P;
57         C c;
58         C::const_iterator e = c.end();
59         R r = c.insert(e, P(3));
60         assert(c.size() == 1);
61         assert(*r == 3);
62 
63         r = c.insert(r, P(3));
64         assert(c.size() == 1);
65         assert(*r == 3);
66 
67         r = c.insert(e, P(4));
68         assert(c.size() == 2);
69         assert(*r == 4);
70 
71         r = c.insert(e, P(5));
72         assert(c.size() == 3);
73         assert(*r == 5);
74     }
75 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
76 #if __cplusplus >= 201103L
77     {
78         typedef std::unordered_set<double, std::hash<double>,
79                                 std::equal_to<double>, min_allocator<double>> C;
80         typedef C::iterator R;
81         typedef double P;
82         C c;
83         C::const_iterator e = c.end();
84         R r = c.insert(e, P(3.5));
85         assert(c.size() == 1);
86         assert(*r == 3.5);
87 
88         r = c.insert(r, P(3.5));
89         assert(c.size() == 1);
90         assert(*r == 3.5);
91 
92         r = c.insert(e, P(4.5));
93         assert(c.size() == 2);
94         assert(*r == 4.5);
95 
96         r = c.insert(e, P(5.5));
97         assert(c.size() == 3);
98         assert(*r == 5.5);
99     }
100 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
101     {
102         typedef std::unordered_set<MoveOnly, std::hash<MoveOnly>,
103                             std::equal_to<MoveOnly>, min_allocator<MoveOnly>> C;
104         typedef C::iterator R;
105         typedef MoveOnly P;
106         C c;
107         C::const_iterator e = c.end();
108         R r = c.insert(e, P(3));
109         assert(c.size() == 1);
110         assert(*r == 3);
111 
112         r = c.insert(r, P(3));
113         assert(c.size() == 1);
114         assert(*r == 3);
115 
116         r = c.insert(e, P(4));
117         assert(c.size() == 2);
118         assert(*r == 4);
119 
120         r = c.insert(e, P(5));
121         assert(c.size() == 3);
122         assert(*r == 5);
123     }
124 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
125 #if _LIBCPP_DEBUG >= 1
126     {
127         typedef std::unordered_set<double> C;
128         typedef C::iterator R;
129         typedef C::value_type P;
130         C c;
131         C c2;
132         C::const_iterator e = c2.end();
133         R r = c.insert(e, P(3.5));
134         assert(false);
135     }
136 #endif
137 #endif
138 }
139