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// UNSUPPORTED: c++03
10
11// <unordered_map>
12
13// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
14// class Alloc = allocator<pair<const Key, T>>>
15// class unordered_map
16
17// void insert(initializer_list<value_type> il);
18
19#include <unordered_map>
20#include <string>
21#include <cassert>
22
23#include "test_macros.h"
24#include "test_iterators.h"
25#include "min_allocator.h"
26
27int main(int, char**) {
28 {
29 typedef std::unordered_map<int, std::string> C;
30 typedef std::pair<int, std::string> P;
31 C c;
32 c.insert(l: {
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 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 {
47 typedef std::unordered_map<int,
48 std::string,
49 std::hash<int>,
50 std::equal_to<int>,
51 min_allocator<std::pair<const int, std::string>>>
52 C;
53 typedef std::pair<int, std::string> P;
54 C c;
55 c.insert({
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 assert(c.size() == 4);
64 assert(c.at(1) == "one");
65 assert(c.at(2) == "two");
66 assert(c.at(3) == "three");
67 assert(c.at(4) == "four");
68 }
69
70 return 0;
71}
72

source code of libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_init.pass.cpp