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