]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/associative/multiset/insert_node_type.pass.cpp
Vendor import of libc++ trunk r338536:
[FreeBSD/FreeBSD.git] / test / std / containers / associative / multiset / insert_node_type.pass.cpp
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 // iterator insert(node_type&&);
17
18 #include <set>
19 #include <type_traits>
20 #include "min_allocator.h"
21
22 template <class Container>
23 typename Container::node_type
24 node_factory(typename Container::key_type const& key)
25 {
26     static Container c;
27     auto it = c.insert(key);
28     return c.extract(it);
29 }
30
31 template <class Container>
32 void test(Container& c)
33 {
34     auto* nf = &node_factory<Container>;
35
36     for (int i = 0; i != 10; ++i)
37     {
38         typename Container::node_type node = nf(i);
39         assert(!node.empty());
40         typename Container::iterator it = c.insert(std::move(node));
41         assert(node.empty());
42         assert(it == c.find(i) && it != c.end());
43         assert(*it == i);
44         assert(node.empty());
45     }
46
47     assert(c.size() == 10);
48
49     { // Insert empty node.
50         typename Container::node_type def;
51         auto it = c.insert(std::move(def));
52         assert(def.empty());
53         assert(it == c.end());
54     }
55
56     { // Insert duplicate node.
57         typename Container::node_type dupl = nf(0);
58         auto it = c.insert(std::move(dupl));
59         assert(*it == 0);
60     }
61
62     assert(c.size() == 11);
63
64     assert(c.count(0) == 2);
65     for (int i = 1; i != 10; ++i)
66     {
67         assert(c.count(i) == 1);
68     }
69 }
70
71 int main()
72 {
73     std::multiset<int> m;
74     test(m);
75     std::multiset<int, std::less<int>, min_allocator<int>> m2;
76     test(m2);
77 }