1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <unordered_map> |
10 | |
11 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
12 | // class Alloc = allocator<pair<const Key, T>>> |
13 | // class unordered_map |
14 | |
15 | // template <class InputIterator> |
16 | // void insert(InputIterator first, InputIterator last); |
17 | |
18 | #include <unordered_map> |
19 | #include <string> |
20 | #include <cassert> |
21 | |
22 | #include "test_macros.h" |
23 | #include "test_iterators.h" |
24 | #include "min_allocator.h" |
25 | |
26 | int main(int, char**) |
27 | { |
28 | { |
29 | typedef std::unordered_map<int, std::string> C; |
30 | typedef std::pair<int, std::string> P; |
31 | P a[] = |
32 | { |
33 | P(1, "one" ), |
34 | P(2, "two" ), |
35 | P(3, "three" ), |
36 | P(4, "four" ), |
37 | P(1, "four" ), |
38 | P(2, "four" ), |
39 | }; |
40 | C c; |
41 | c.insert(cpp17_input_iterator<P*>(a), cpp17_input_iterator<P*>(a + sizeof(a)/sizeof(a[0]))); |
42 | assert(c.size() == 4); |
43 | assert(c.at(1) == "one" ); |
44 | assert(c.at(2) == "two" ); |
45 | assert(c.at(3) == "three" ); |
46 | assert(c.at(4) == "four" ); |
47 | } |
48 | #if TEST_STD_VER >= 11 |
49 | { |
50 | typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, |
51 | min_allocator<std::pair<const int, std::string>>> C; |
52 | typedef std::pair<int, std::string> P; |
53 | P a[] = |
54 | { |
55 | P(1, "one" ), |
56 | P(2, "two" ), |
57 | P(3, "three" ), |
58 | P(4, "four" ), |
59 | P(1, "four" ), |
60 | P(2, "four" ), |
61 | }; |
62 | C c; |
63 | c.insert(cpp17_input_iterator<P*>(a), cpp17_input_iterator<P*>(a + sizeof(a)/sizeof(a[0]))); |
64 | assert(c.size() == 4); |
65 | assert(c.at(1) == "one" ); |
66 | assert(c.at(2) == "two" ); |
67 | assert(c.at(3) == "three" ); |
68 | assert(c.at(4) == "four" ); |
69 | } |
70 | #endif |
71 | |
72 | return 0; |
73 | } |
74 | |