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 // <map>
12 
13 // class map
14 
15 // node_type extract(const_iterator);
16 
17 #include <map>
18 #include "min_allocator.h"
19 #include "Counter.h"
20 
21 template <class Container>
22 void test(Container& c)
23 {
24     size_t sz = c.size();
25 
26     auto some_key = c.cbegin()->first;
27 
28     for (auto first = c.cbegin(); first != c.cend();)
29     {
30         auto key_value = first->first;
31         typename Container::node_type t = c.extract(first++);
32         --sz;
33         assert(t.key() == key_value);
34         t.key() = some_key;
35         assert(t.key() == some_key);
36         assert(t.get_allocator() == c.get_allocator());
37         assert(sz == c.size());
38     }
39 
40     assert(c.size() == 0);
41 }
42 
43 int main(int, char**)
44 {
45     {
46         using map_type = std::map<int, int>;
47         map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}};
48         test(m);
49     }
50 
51     {
52         std::map<Counter<int>, Counter<int>> m =
53             {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}};
54         assert(Counter_base::gConstructed == 12);
55         test(m);
56         assert(Counter_base::gConstructed == 0);
57     }
58 
59     {
60         using min_alloc_map =
61             std::map<int, int, std::less<int>,
62                      min_allocator<std::pair<const int, int>>>;
63         min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}};
64         test(m);
65     }
66 
67   return 0;
68 }
69