Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / unord / unord.set / insert_rvalue.pass.cpp
blob9edab2740415576ce3fbc205c1627b57e34bfa80
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 //===----------------------------------------------------------------------===//
9 // <unordered_set>
11 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
12 // class Alloc = allocator<Value>>
13 // class unordered_set
15 // pair<iterator, bool> insert(value_type&& x);
17 #include <unordered_set>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "MoveOnly.h"
22 #include "min_allocator.h"
24 int main(int, char**)
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(P(3.5));
32 assert(c.size() == 1);
33 assert(*r.first == 3.5);
34 assert(r.second);
36 r = c.insert(P(3.5));
37 assert(c.size() == 1);
38 assert(*r.first == 3.5);
39 assert(!r.second);
41 r = c.insert(P(4.5));
42 assert(c.size() == 2);
43 assert(*r.first == 4.5);
44 assert(r.second);
46 r = c.insert(P(5.5));
47 assert(c.size() == 3);
48 assert(*r.first == 5.5);
49 assert(r.second);
51 #if TEST_STD_VER >= 11
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);
62 r = c.insert(P(3));
63 assert(c.size() == 1);
64 assert(*r.first == 3);
65 assert(!r.second);
67 r = c.insert(P(4));
68 assert(c.size() == 2);
69 assert(*r.first == 4);
70 assert(r.second);
72 r = c.insert(P(5));
73 assert(c.size() == 3);
74 assert(*r.first == 5);
75 assert(r.second);
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);
88 r = c.insert(P(3.5));
89 assert(c.size() == 1);
90 assert(*r.first == 3.5);
91 assert(!r.second);
93 r = c.insert(P(4.5));
94 assert(c.size() == 2);
95 assert(*r.first == 4.5);
96 assert(r.second);
98 r = c.insert(P(5.5));
99 assert(c.size() == 3);
100 assert(*r.first == 5.5);
101 assert(r.second);
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);
114 r = c.insert(P(3));
115 assert(c.size() == 1);
116 assert(*r.first == 3);
117 assert(!r.second);
119 r = c.insert(P(4));
120 assert(c.size() == 2);
121 assert(*r.first == 4);
122 assert(r.second);
124 r = c.insert(P(5));
125 assert(c.size() == 3);
126 assert(*r.first == 5);
127 assert(r.second);
129 #endif // TEST_STD_VER >= 11
131 return 0;