Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / unord / unord.set / extract_key.pass.cpp
blob3bfb6c358c8b699e033d63cc2867b0f5d7d450a9
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 // UNSUPPORTED: c++03, c++11, c++14
11 // <unordered_set>
13 // class unordered_set
15 // node_type extract(key_type const&);
17 #include <unordered_set>
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "Counter.h"
22 template <class Container, class KeyTypeIter>
23 void test(Container& c, KeyTypeIter first, KeyTypeIter last)
25 std::size_t sz = c.size();
26 assert((std::size_t)std::distance(first, last) == sz);
28 for (KeyTypeIter copy = first; copy != last; ++copy)
30 typename Container::node_type t = c.extract(*copy);
31 assert(!t.empty());
32 --sz;
33 assert(t.value() == *copy);
34 assert(t.get_allocator() == c.get_allocator());
35 assert(sz == c.size());
38 assert(c.size() == 0);
40 for (KeyTypeIter copy = first; copy != last; ++copy)
42 typename Container::node_type t = c.extract(*copy);
43 assert(t.empty());
47 int main(int, char**)
50 std::unordered_set<int> m = {1, 2, 3, 4, 5, 6};
51 int keys[] = {1, 2, 3, 4, 5, 6};
52 test(m, std::begin(keys), std::end(keys));
56 std::unordered_set<Counter<int>> m = {1, 2, 3, 4, 5, 6};
58 Counter<int> keys[] = {1, 2, 3, 4, 5, 6};
59 assert(Counter_base::gConstructed == 6+6);
60 test(m, std::begin(keys), std::end(keys));
62 assert(Counter_base::gConstructed == 0);
66 using min_alloc_set = std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>;
67 min_alloc_set m = {1, 2, 3, 4, 5, 6};
68 int keys[] = {1, 2, 3, 4, 5, 6};
69 test(m, std::begin(keys), std::end(keys));
72 return 0;