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 | typedef std::unordered_map<int, std::string> C; |
29 | typedef std::pair<int, std::string> P; |
30 | P a[] = { |
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; |
39 | c.insert(cpp17_input_iterator<P*>(a), cpp17_input_iterator<P*>(a + sizeof(a) / sizeof(a[0]))); |
40 | assert(c.size() == 4); |
41 | assert(c.at(1) == "one" ); |
42 | assert(c.at(2) == "two" ); |
43 | assert(c.at(3) == "three" ); |
44 | assert(c.at(4) == "four" ); |
45 | } |
46 | #if TEST_STD_VER >= 11 |
47 | { |
48 | typedef std::unordered_map<int, |
49 | std::string, |
50 | std::hash<int>, |
51 | std::equal_to<int>, |
52 | min_allocator<std::pair<const int, std::string>>> |
53 | C; |
54 | typedef std::pair<int, std::string> P; |
55 | P a[] = { |
56 | P(1, "one" ), |
57 | P(2, "two" ), |
58 | P(3, "three" ), |
59 | P(4, "four" ), |
60 | P(1, "four" ), |
61 | P(2, "four" ), |
62 | }; |
63 | C c; |
64 | c.insert(cpp17_input_iterator<P*>(a), cpp17_input_iterator<P*>(a + sizeof(a) / sizeof(a[0]))); |
65 | assert(c.size() == 4); |
66 | assert(c.at(1) == "one" ); |
67 | assert(c.at(2) == "two" ); |
68 | assert(c.at(3) == "three" ); |
69 | assert(c.at(4) == "four" ); |
70 | } |
71 | #endif |
72 | |
73 | return 0; |
74 | } |
75 | |