]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / unord / unord.multimap / unord.multimap.modifiers / insert_range.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 // <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 #include <cstddef>
23
24 #include "test_iterators.h"
25 #include "min_allocator.h"
26
27 int main()
28 {
29     {
30         typedef std::unordered_multimap<int, std::string> C;
31         typedef std::pair<int, std::string> P;
32         P a[] =
33         {
34             P(1, "one"),
35             P(2, "two"),
36             P(3, "three"),
37             P(4, "four"),
38             P(1, "four"),
39             P(2, "four"),
40         };
41         C c;
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");
50         ++k;
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);
55         k = eq.first;
56         assert(k->first == 2);
57         assert(k->second == "two");
58         ++k;
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);
63         k = eq.first;
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);
68         k = eq.first;
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());
73     }
74 #if TEST_STD_VER >= 11
75     {
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;
79         P a[] =
80         {
81             P(1, "one"),
82             P(2, "two"),
83             P(3, "three"),
84             P(4, "four"),
85             P(1, "four"),
86             P(2, "four"),
87         };
88         C c;
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");
97         ++k;
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);
102         k = eq.first;
103         assert(k->first == 2);
104         assert(k->second == "two");
105         ++k;
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);
110         k = eq.first;
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);
115         k = eq.first;
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());
120     }
121 #endif
122 }