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// template <class... Args>
18// pair<iterator, bool> emplace(Args&&... args);
19
20#include <unordered_map>
21#include <cassert>
22
23#include "test_macros.h"
24#include "../../../Emplaceable.h"
25#include "min_allocator.h"
26
27int main(int, char**)
28{
29 {
30 typedef std::unordered_map<int, Emplaceable> C;
31 typedef std::pair<C::iterator, bool> R;
32 C c;
33 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 3),
34 std::forward_as_tuple());
35 assert(r.second);
36 assert(c.size() == 1);
37 assert(r.first->first == 3);
38 assert(r.first->second == Emplaceable());
39
40 r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
41 assert(r.second);
42 assert(c.size() == 2);
43 assert(r.first->first == 4);
44 assert(r.first->second == Emplaceable(5, 6));
45
46 r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 5),
47 std::forward_as_tuple(args: 6, args: 7));
48 assert(r.second);
49 assert(c.size() == 3);
50 assert(r.first->first == 5);
51 assert(r.first->second == Emplaceable(6, 7));
52 }
53 {
54 typedef std::unordered_map<int, Emplaceable, std::hash<int>, std::equal_to<int>,
55 min_allocator<std::pair<const int, Emplaceable>>> C;
56 typedef std::pair<C::iterator, bool> R;
57 C c;
58 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 3),
59 std::forward_as_tuple());
60 assert(r.second);
61 assert(c.size() == 1);
62 assert(r.first->first == 3);
63 assert(r.first->second == Emplaceable());
64
65 r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
66 assert(r.second);
67 assert(c.size() == 2);
68 assert(r.first->first == 4);
69 assert(r.first->second == Emplaceable(5, 6));
70
71 r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 5),
72 std::forward_as_tuple(args: 6, args: 7));
73 assert(r.second);
74 assert(c.size() == 3);
75 assert(r.first->first == 5);
76 assert(r.first->second == Emplaceable(6, 7));
77 }
78
79 return 0;
80}
81

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