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