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(key_type const&); 16 17 #include <map> 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.key() == *copy); 33 t.key() = *first; // We should be able to mutate key. 34 assert(t.key() == *first); 35 assert(t.get_allocator() == c.get_allocator()); 36 assert(sz == c.size()); 37 } 38 39 assert(c.size() == 0); 40 41 for (KeyTypeIter copy = first; copy != last; ++copy) 42 { 43 typename Container::node_type t = c.extract(*copy); 44 assert(t.empty()); 45 } 46 } 47 48 int main(int, char**) 49 { 50 { 51 std::map<int, int> m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; 52 int keys[] = {1, 2, 3, 4, 5, 6}; 53 test(m, std::begin(keys), std::end(keys)); 54 } 55 56 { 57 std::map<Counter<int>, Counter<int>> m = 58 {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}}; 59 { 60 Counter<int> keys[] = {1, 2, 3, 4, 5, 6}; 61 assert(Counter_base::gConstructed == 12+6); 62 test(m, std::begin(keys), std::end(keys)); 63 } 64 assert(Counter_base::gConstructed == 0); 65 } 66 67 { 68 using min_alloc_map = 69 std::map<int, int, std::less<int>, 70 min_allocator<std::pair<const int, int>>>; 71 min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}; 72 int keys[] = {1, 2, 3, 4, 5, 6}; 73 test(m, std::begin(keys), std::end(keys)); 74 } 75 76 return 0; 77 } 78