• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 
12 // <set>
13 
14 // class multiset
15 
16 // node_type extract(key_type const&);
17 
18 #include <set>
19 #include "min_allocator.h"
20 #include "Counter.h"
21 
22 template <class Container, class KeyTypeIter>
test(Container & c,KeyTypeIter first,KeyTypeIter last)23 void test(Container& c, KeyTypeIter first, KeyTypeIter last)
24 {
25     size_t sz = c.size();
26     assert((size_t)std::distance(first, last) == sz);
27 
28     for (KeyTypeIter copy = first; copy != last; ++copy)
29     {
30         typename Container::node_type t = c.extract(*copy);
31         assert(!t.empty());
32         --sz;
33         assert(t.value() == *copy);
34         assert(t.get_allocator() == c.get_allocator());
35         assert(sz == c.size());
36     }
37 
38     assert(c.size() == 0);
39 
40     for (KeyTypeIter copy = first; copy != last; ++copy)
41     {
42         typename Container::node_type t = c.extract(*copy);
43         assert(t.empty());
44     }
45 }
46 
main()47 int main()
48 {
49     {
50         std::multiset<int> m = {1, 2, 3, 4, 5, 6};
51         int keys[] = {1, 2, 3, 4, 5, 6};
52         test(m, std::begin(keys), std::end(keys));
53     }
54 
55     {
56         std::multiset<Counter<int>> m = {1, 2, 3, 4, 5, 6};
57         {
58             Counter<int> keys[] = {1, 2, 3, 4, 5, 6};
59             assert(Counter_base::gConstructed == 6+6);
60             test(m, std::begin(keys), std::end(keys));
61         }
62         assert(Counter_base::gConstructed == 0);
63     }
64 
65     {
66         using min_alloc_set = std::multiset<int, std::less<int>, min_allocator<int>>;
67         min_alloc_set m = {1, 2, 3, 4, 5, 6};
68         int keys[] = {1, 2, 3, 4, 5, 6};
69         test(m, std::begin(keys), std::end(keys));
70     }
71 }
72