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// pair<iterator, bool> insert(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
24int main(int, char**)
25{
26 {
27 typedef std::unordered_set<double> C;
28 typedef std::pair<C::iterator, bool> R;
29 typedef double P;
30 C c;
31 R r = c.insert(x: P(3.5));
32 assert(c.size() == 1);
33 assert(*r.first == 3.5);
34 assert(r.second);
35
36 r = c.insert(x: P(3.5));
37 assert(c.size() == 1);
38 assert(*r.first == 3.5);
39 assert(!r.second);
40
41 r = c.insert(x: P(4.5));
42 assert(c.size() == 2);
43 assert(*r.first == 4.5);
44 assert(r.second);
45
46 r = c.insert(x: P(5.5));
47 assert(c.size() == 3);
48 assert(*r.first == 5.5);
49 assert(r.second);
50 }
51#if TEST_STD_VER >= 11
52 {
53 typedef std::unordered_set<MoveOnly> C;
54 typedef std::pair<C::iterator, bool> R;
55 typedef MoveOnly P;
56 C c;
57 R r = c.insert(P(3));
58 assert(c.size() == 1);
59 assert(*r.first == 3);
60 assert(r.second);
61
62 r = c.insert(P(3));
63 assert(c.size() == 1);
64 assert(*r.first == 3);
65 assert(!r.second);
66
67 r = c.insert(P(4));
68 assert(c.size() == 2);
69 assert(*r.first == 4);
70 assert(r.second);
71
72 r = c.insert(P(5));
73 assert(c.size() == 3);
74 assert(*r.first == 5);
75 assert(r.second);
76 }
77 {
78 typedef std::unordered_set<double, std::hash<double>,
79 std::equal_to<double>, min_allocator<double>> C;
80 typedef std::pair<C::iterator, bool> R;
81 typedef double P;
82 C c;
83 R r = c.insert(P(3.5));
84 assert(c.size() == 1);
85 assert(*r.first == 3.5);
86 assert(r.second);
87
88 r = c.insert(P(3.5));
89 assert(c.size() == 1);
90 assert(*r.first == 3.5);
91 assert(!r.second);
92
93 r = c.insert(P(4.5));
94 assert(c.size() == 2);
95 assert(*r.first == 4.5);
96 assert(r.second);
97
98 r = c.insert(P(5.5));
99 assert(c.size() == 3);
100 assert(*r.first == 5.5);
101 assert(r.second);
102 }
103 {
104 typedef std::unordered_set<MoveOnly, std::hash<MoveOnly>,
105 std::equal_to<MoveOnly>, min_allocator<MoveOnly>> C;
106 typedef std::pair<C::iterator, bool> R;
107 typedef MoveOnly P;
108 C c;
109 R r = c.insert(P(3));
110 assert(c.size() == 1);
111 assert(*r.first == 3);
112 assert(r.second);
113
114 r = c.insert(P(3));
115 assert(c.size() == 1);
116 assert(*r.first == 3);
117 assert(!r.second);
118
119 r = c.insert(P(4));
120 assert(c.size() == 2);
121 assert(*r.first == 4);
122 assert(r.second);
123
124 r = c.insert(P(5));
125 assert(c.size() == 3);
126 assert(*r.first == 5);
127 assert(r.second);
128 }
129#endif // TEST_STD_VER >= 11
130
131 return 0;
132}
133

source code of libcxx/test/std/containers/unord/unord.set/insert_rvalue.pass.cpp