]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/associative/multimap/multimap.modifiers/insert_node_type_hint.pass.cpp
Vendor import of libc++ trunk r338536:
[FreeBSD/FreeBSD.git] / test / std / containers / associative / multimap / multimap.modifiers / insert_node_type_hint.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 // <map>
13
14 // class multimap
15
16 // iterator insert(const_iterator hint, node_type&&);
17
18 #include <map>
19 #include "min_allocator.h"
20
21 template <class Container>
22 typename Container::node_type
23 node_factory(typename Container::key_type const& key,
24              typename Container::mapped_type const& mapped)
25 {
26     static Container c;
27     auto it = c.insert({key, mapped});
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, i + 1);
39         assert(!node.empty());
40         size_t prev = c.size();
41         auto it = c.insert(c.end(), std::move(node));
42         assert(node.empty());
43         assert(prev + 1 == c.size());
44         assert(it == c.find(i));
45         assert(it->first == i);
46         assert(it->second == i + 1);
47     }
48
49     assert(c.size() == 10);
50
51     for (int i = 0; i != 10; ++i)
52     {
53         assert(c.count(i) == 1);
54         assert(c.find(i)->second == i + 1);
55     }
56 }
57
58 int main()
59 {
60     std::multimap<int, int> m;
61     test(m);
62     std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>> m2;
63     test(m2);
64 }