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