Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / unord / unord.set / insert_hint_rvalue.pass.cpp
blobde67a912dc92ca035726ede3cd6887c7db7ca0cd
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 // iterator insert(const_iterator p, 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 C::iterator R;
29 typedef double P;
30 C c;
31 typename C::const_iterator e = c.end();
32 R r = c.insert(e, P(3.5));
33 assert(c.size() == 1);
34 assert(*r == 3.5);
36 r = c.insert(r, P(3.5));
37 assert(c.size() == 1);
38 assert(*r == 3.5);
40 r = c.insert(c.end(), P(4.5));
41 assert(c.size() == 2);
42 assert(*r == 4.5);
44 r = c.insert(c.end(), P(5.5));
45 assert(c.size() == 3);
46 assert(*r == 5.5);
48 #if TEST_STD_VER >= 11
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);
59 r = c.insert(r, P(3));
60 assert(c.size() == 1);
61 assert(*r == 3);
63 r = c.insert(c.end(), P(4));
64 assert(c.size() == 2);
65 assert(*r == 4);
67 r = c.insert(c.end(), P(5));
68 assert(c.size() == 3);
69 assert(*r == 5);
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);
82 r = c.insert(r, P(3.5));
83 assert(c.size() == 1);
84 assert(*r == 3.5);
86 r = c.insert(c.end(), P(4.5));
87 assert(c.size() == 2);
88 assert(*r == 4.5);
90 r = c.insert(c.end(), P(5.5));
91 assert(c.size() == 3);
92 assert(*r == 5.5);
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);
105 r = c.insert(r, P(3));
106 assert(c.size() == 1);
107 assert(*r == 3);
109 r = c.insert(c.end(), P(4));
110 assert(c.size() == 2);
111 assert(*r == 4);
113 r = c.insert(c.end(), P(5));
114 assert(c.size() == 3);
115 assert(*r == 5);
117 #endif // TEST_STD_VER >= 11
119 return 0;