]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/associative/set/extract_iterator.pass.cpp
Vendor import of libc++ trunk r338536:
[FreeBSD/FreeBSD.git] / test / std / containers / associative / set / extract_iterator.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11
12 // <set>
13
14 // class set
15
16 // node_type extract(const_iterator);
17
18 #include <set>
19 #include "min_allocator.h"
20 #include "Counter.h"
21
22 template <class Container>
23 void test(Container& c)
24 {
25     size_t sz = c.size();
26
27     for (auto first = c.cbegin(); first != c.cend();)
28     {
29         auto key_value = *first;
30         typename Container::node_type t = c.extract(first++);
31         --sz;
32         assert(t.value() == key_value);
33         assert(t.get_allocator() == c.get_allocator());
34         assert(sz == c.size());
35     }
36
37     assert(c.size() == 0);
38 }
39
40 int main()
41 {
42     {
43         using set_type = std::set<int>;
44         set_type m = {1, 2, 3, 4, 5, 6};
45         test(m);
46     }
47
48     {
49         std::set<Counter<int>> m = {1, 2, 3, 4, 5, 6};
50         assert(Counter_base::gConstructed == 6);
51         test(m);
52         assert(Counter_base::gConstructed == 0);
53     }
54
55     {
56         using min_alloc_set = std::set<int, std::less<int>, min_allocator<int>>;
57         min_alloc_set m = {1, 2, 3, 4, 5, 6};
58         test(m);
59     }
60 }