| 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 |
// <unordered_set> |
| 12 |
|
| 13 |
// class unordered_multiset |
| 14 |
|
| 15 |
// node_type extract(const_iterator); |
| 16 |
|
| 17 |
#include <unordered_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 |
{ |
| 25 |
std::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(int, char**) |
| 41 |
{ |
| 42 |
{ |
| 43 |
using set_type = std::unordered_multiset<int>; |
| 44 |
set_type m = {1, 2, 3, 4, 5, 6}; |
| 45 |
test(m); |
| 46 |
} |
| 47 |
|
| 48 |
{ |
| 49 |
std::unordered_multiset<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::unordered_multiset<int, std::hash<int>, std::equal_to<int>, min_allocator<int>>; |
| 57 |
min_alloc_set m = {1, 2, 3, 4, 5, 6}; |
| 58 |
test(m); |
| 59 |
} |
| 60 |
|
| 61 |
return 0; |
| 62 |
} |