1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
17 // template <class... Args>
18 // pair<iterator, bool> emplace(Args&&... args);
20 #include <unordered_map>
23 #include "test_macros.h"
24 #include "../../../Emplaceable.h"
25 #include "min_allocator.h"
30 typedef std::unordered_map
<int, Emplaceable
> C
;
31 typedef std::pair
<C::iterator
, bool> R
;
33 R r
= c
.emplace(std::piecewise_construct
, std::forward_as_tuple(3),
34 std::forward_as_tuple());
36 assert(c
.size() == 1);
37 assert(r
.first
->first
== 3);
38 assert(r
.first
->second
== Emplaceable());
40 r
= c
.emplace(std::pair
<const int, Emplaceable
>(4, Emplaceable(5, 6)));
42 assert(c
.size() == 2);
43 assert(r
.first
->first
== 4);
44 assert(r
.first
->second
== Emplaceable(5, 6));
46 r
= c
.emplace(std::piecewise_construct
, std::forward_as_tuple(5),
47 std::forward_as_tuple(6, 7));
49 assert(c
.size() == 3);
50 assert(r
.first
->first
== 5);
51 assert(r
.first
->second
== Emplaceable(6, 7));
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
;
58 R r
= c
.emplace(std::piecewise_construct
, std::forward_as_tuple(3),
59 std::forward_as_tuple());
61 assert(c
.size() == 1);
62 assert(r
.first
->first
== 3);
63 assert(r
.first
->second
== Emplaceable());
65 r
= c
.emplace(std::pair
<const int, Emplaceable
>(4, Emplaceable(5, 6)));
67 assert(c
.size() == 2);
68 assert(r
.first
->first
== 4);
69 assert(r
.first
->second
== Emplaceable(5, 6));
71 r
= c
.emplace(std::piecewise_construct
, std::forward_as_tuple(5),
72 std::forward_as_tuple(6, 7));
74 assert(c
.size() == 3);
75 assert(r
.first
->first
== 5);
76 assert(r
.first
->second
== Emplaceable(6, 7));