1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
16 // template <class InputIterator>
17 // void insert(InputIterator first, InputIterator last);
19 #include <unordered_map>
24 #include "test_iterators.h"
25 #include "min_allocator.h"
30 typedef std::unordered_multimap<int, std::string> C;
31 typedef std::pair<int, std::string> P;
42 c.insert(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
43 assert(c.size() == 6);
44 typedef std::pair<C::iterator, C::iterator> Eq;
45 Eq eq = c.equal_range(1);
46 assert(std::distance(eq.first, eq.second) == 2);
47 C::iterator k = eq.first;
48 assert(k->first == 1);
49 assert(k->second == "one");
51 assert(k->first == 1);
52 assert(k->second == "four");
53 eq = c.equal_range(2);
54 assert(std::distance(eq.first, eq.second) == 2);
56 assert(k->first == 2);
57 assert(k->second == "two");
59 assert(k->first == 2);
60 assert(k->second == "four");
61 eq = c.equal_range(3);
62 assert(std::distance(eq.first, eq.second) == 1);
64 assert(k->first == 3);
65 assert(k->second == "three");
66 eq = c.equal_range(4);
67 assert(std::distance(eq.first, eq.second) == 1);
69 assert(k->first == 4);
70 assert(k->second == "four");
71 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
72 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
74 #if TEST_STD_VER >= 11
76 typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
77 min_allocator<std::pair<const int, std::string>>> C;
78 typedef std::pair<int, std::string> P;
89 c.insert(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
90 assert(c.size() == 6);
91 typedef std::pair<C::iterator, C::iterator> Eq;
92 Eq eq = c.equal_range(1);
93 assert(std::distance(eq.first, eq.second) == 2);
94 C::iterator k = eq.first;
95 assert(k->first == 1);
96 assert(k->second == "one");
98 assert(k->first == 1);
99 assert(k->second == "four");
100 eq = c.equal_range(2);
101 assert(std::distance(eq.first, eq.second) == 2);
103 assert(k->first == 2);
104 assert(k->second == "two");
106 assert(k->first == 2);
107 assert(k->second == "four");
108 eq = c.equal_range(3);
109 assert(std::distance(eq.first, eq.second) == 1);
111 assert(k->first == 3);
112 assert(k->second == "three");
113 eq = c.equal_range(4);
114 assert(std::distance(eq.first, eq.second) == 1);
116 assert(k->first == 4);
117 assert(k->second == "four");
118 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
119 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());