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 // UNSUPPORTED: c++98, c++03, c++11, c++14
10 
11 // <set>
12 
13 // class set
14 
15 // node_type extract(key_type const&);
16 
17 #include <set>
18 #include "min_allocator.h"
19 #include "Counter.h"
20 
21 template <class Container, class KeyTypeIter>
22 void test(Container& c, KeyTypeIter first, KeyTypeIter last)
23 {
24     size_t sz = c.size();
25     assert((size_t)std::distance(first, last) == sz);
26 
27     for (KeyTypeIter copy = first; copy != last; ++copy)
28     {
29         typename Container::node_type t = c.extract(*copy);
30         assert(!t.empty());
31         --sz;
32         assert(t.value() == *copy);
33         assert(t.get_allocator() == c.get_allocator());
34         assert(sz == c.size());
35     }
36 
37     assert(c.size() == 0);
38 
39     for (KeyTypeIter copy = first; copy != last; ++copy)
40     {
41         typename Container::node_type t = c.extract(*copy);
42         assert(t.empty());
43     }
44 }
45 
46 int main(int, char**)
47 {
48     {
49         std::set<int> m = {1, 2, 3, 4, 5, 6};
50         int keys[] = {1, 2, 3, 4, 5, 6};
51         test(m, std::begin(keys), std::end(keys));
52     }
53 
54     {
55         std::set<Counter<int>> m = {1, 2, 3, 4, 5, 6};
56         {
57             Counter<int> keys[] = {1, 2, 3, 4, 5, 6};
58             assert(Counter_base::gConstructed == 6+6);
59             test(m, std::begin(keys), std::end(keys));
60         }
61         assert(Counter_base::gConstructed == 0);
62     }
63 
64     {
65         using min_alloc_set = std::set<int, std::less<int>, min_allocator<int>>;
66         min_alloc_set m = {1, 2, 3, 4, 5, 6};
67         int keys[] = {1, 2, 3, 4, 5, 6};
68         test(m, std::begin(keys), std::end(keys));
69     }
70 
71   return 0;
72 }
73