aboutsummaryrefslogtreecommitdiff
path: root/test/std/containers/associative/multimap/multimap.modifiers/insert_node_type.pass.cpp
blob: 9067705141963fe13b4418242633c8968c71c8bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03, c++11, c++14

// <map>

// class multimap

// iterator insert(node_type&&);

#include <map>
#include <type_traits>
#include "min_allocator.h"

template <class Container>
typename Container::node_type
node_factory(typename Container::key_type const& key,
             typename Container::mapped_type const& mapped)
{
    static Container c;
    auto it = c.insert({key, mapped});
    return c.extract(it);
}

template <class Container>
void test(Container& c)
{
    auto* nf = &node_factory<Container>;

    for (int i = 0; i != 10; ++i)
    {
        typename Container::node_type node = nf(i, i + 1);
        assert(!node.empty());
        typename Container::iterator it = c.insert(std::move(node));
        assert(node.empty());
        assert(it == c.find(i) && it != c.end());
    }

    assert(c.size() == 10);

    { // Insert empty node.
        typename Container::node_type def;
        auto it = c.insert(std::move(def));
        assert(def.empty());
        assert(it == c.end());
    }

    { // Insert duplicate node.
        typename Container::node_type dupl = nf(0, 42);
        auto it = c.insert(std::move(dupl));
        assert(dupl.empty());
        assert(it != c.end());
        assert(it->second == 42);
    }

    assert(c.size() == 11);
    assert(c.count(0) == 2);
    for (int i = 1; i != 10; ++i)
    {
        assert(c.count(i) == 1);
        assert(c.find(i)->second == i + 1);
    }
}

int main()
{
    std::multimap<int, int> m;
    test(m);
    std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>> m2;
    test(m2);
}