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// iterator erase(const_iterator p)
17
18#include <unordered_map>
19#include <string>
20#include <cassert>
21
22#include "min_allocator.h"
23
24int main()
25{
26    {
27        typedef std::unordered_multimap<int, std::string> C;
28        typedef std::pair<int, std::string> P;
29        P a[] =
30        {
31            P(1, "one"),
32            P(2, "two"),
33            P(3, "three"),
34            P(4, "four"),
35            P(1, "four"),
36            P(2, "four"),
37        };
38        C c(a, a + sizeof(a)/sizeof(a[0]));
39        C::const_iterator i = c.find(2);
40        C::iterator j = c.erase(i);
41
42        assert(c.size() == 5);
43        typedef std::pair<C::const_iterator, C::const_iterator> Eq;
44        Eq eq = c.equal_range(1);
45        assert(std::distance(eq.first, eq.second) == 2);
46        C::const_iterator k = eq.first;
47        assert(k->first == 1);
48        assert(k->second == "one");
49        ++k;
50        assert(k->first == 1);
51        assert(k->second == "four");
52        eq = c.equal_range(2);
53        assert(std::distance(eq.first, eq.second) == 1);
54        k = eq.first;
55        assert(k->first == 2);
56        assert(k->second == "four");
57        eq = c.equal_range(3);
58        assert(std::distance(eq.first, eq.second) == 1);
59        k = eq.first;
60        assert(k->first == 3);
61        assert(k->second == "three");
62        eq = c.equal_range(4);
63        assert(std::distance(eq.first, eq.second) == 1);
64        k = eq.first;
65        assert(k->first == 4);
66        assert(k->second == "four");
67        assert(std::distance(c.begin(), c.end()) == c.size());
68        assert(std::distance(c.cbegin(), c.cend()) == c.size());
69    }
70#if __cplusplus >= 201103L
71    {
72        typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
73                            min_allocator<std::pair<const int, std::string>>> C;
74        typedef std::pair<int, std::string> P;
75        P a[] =
76        {
77            P(1, "one"),
78            P(2, "two"),
79            P(3, "three"),
80            P(4, "four"),
81            P(1, "four"),
82            P(2, "four"),
83        };
84        C c(a, a + sizeof(a)/sizeof(a[0]));
85        C::const_iterator i = c.find(2);
86        C::iterator j = c.erase(i);
87
88        assert(c.size() == 5);
89        typedef std::pair<C::const_iterator, C::const_iterator> Eq;
90        Eq eq = c.equal_range(1);
91        assert(std::distance(eq.first, eq.second) == 2);
92        C::const_iterator k = eq.first;
93        assert(k->first == 1);
94        assert(k->second == "one");
95        ++k;
96        assert(k->first == 1);
97        assert(k->second == "four");
98        eq = c.equal_range(2);
99        assert(std::distance(eq.first, eq.second) == 1);
100        k = eq.first;
101        assert(k->first == 2);
102        assert(k->second == "four");
103        eq = c.equal_range(3);
104        assert(std::distance(eq.first, eq.second) == 1);
105        k = eq.first;
106        assert(k->first == 3);
107        assert(k->second == "three");
108        eq = c.equal_range(4);
109        assert(std::distance(eq.first, eq.second) == 1);
110        k = eq.first;
111        assert(k->first == 4);
112        assert(k->second == "four");
113        assert(std::distance(c.begin(), c.end()) == c.size());
114        assert(std::distance(c.cbegin(), c.cend()) == c.size());
115    }
116#endif
117}
118