insert_range.pass.cpp revision a8bf9de8057ad254cc642f33bd7d0a48dc1ae55c
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// <unordered_map>
11
12// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
13//           class Alloc = allocator<pair<const Key, T>>>
14// class unordered_multimap
15
16// template <class InputIterator>
17//     void insert(InputIterator first, InputIterator last);
18
19#include <unordered_map>
20#include <string>
21#include <cassert>
22
23#include "test_iterators.h"
24
25int main()
26{
27    {
28        typedef std::unordered_multimap<int, std::string> C;
29        typedef std::pair<int, std::string> P;
30        P a[] =
31        {
32            P(1, "one"),
33            P(2, "two"),
34            P(3, "three"),
35            P(4, "four"),
36            P(1, "four"),
37            P(2, "four"),
38        };
39        C c;
40        c.insert(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
41        assert(c.size() == 6);
42        typedef std::pair<C::iterator, C::iterator> Eq;
43        Eq eq = c.equal_range(1);
44        assert(std::distance(eq.first, eq.second) == 2);
45        C::iterator k = eq.first;
46        assert(k->first == 1);
47        assert(k->second == "one");
48        ++k;
49        assert(k->first == 1);
50        assert(k->second == "four");
51        eq = c.equal_range(2);
52        assert(std::distance(eq.first, eq.second) == 2);
53        k = eq.first;
54        assert(k->first == 2);
55        assert(k->second == "two");
56        ++k;
57        assert(k->first == 2);
58        assert(k->second == "four");
59        eq = c.equal_range(3);
60        assert(std::distance(eq.first, eq.second) == 1);
61        k = eq.first;
62        assert(k->first == 3);
63        assert(k->second == "three");
64        eq = c.equal_range(4);
65        assert(std::distance(eq.first, eq.second) == 1);
66        k = eq.first;
67        assert(k->first == 4);
68        assert(k->second == "four");
69        assert(std::distance(c.begin(), c.end()) == c.size());
70        assert(std::distance(c.cbegin(), c.cend()) == c.size());
71    }
72}
73