Debian Codegraph @

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

raw
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
27 int main(int, char**) {
28 {
29 typedef std::unordered_map<int, Emplaceable> C;
30 typedef std::pair<C::iterator, bool> R;
31 C c;
32 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), std::forward_as_tuple());
33 assert(r.second);
34 assert(c.size() == 1);
35 assert(r.first->first == 3);
36 assert(r.first->second == Emplaceable());
37
38 r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
39 assert(r.second);
40 assert(c.size() == 2);
41 assert(r.first->first == 4);
42 assert(r.first->second == Emplaceable(5, 6));
43
44 r = c.emplace(std::piecewise_construct, std::forward_as_tuple(5), std::forward_as_tuple(6, 7));
45 assert(r.second);
46 assert(c.size() == 3);
47 assert(r.first->first == 5);
48 assert(r.first->second == Emplaceable(6, 7));
49 }
50 {
51 typedef std::unordered_map<int,
52 Emplaceable,
53 std::hash<int>,
54 std::equal_to<int>,
55 min_allocator<std::pair<const int, Emplaceable>>>
56 C;
57 typedef std::pair<C::iterator, bool> R;
58 C c;
59 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), 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(5), std::forward_as_tuple(6, 7));
72 assert(r.second);
73 assert(c.size() == 3);
74 assert(r.first->first == 5);
75 assert(r.first->second == Emplaceable(6, 7));
76 }
77
78 return 0;
79 }