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