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_multimap
16
17// template <class... Args>
18// iterator 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 typedef std::unordered_multimap<int, Emplaceable> C;
30 typedef C::iterator R;
31 C c;
32 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 3), std::forward_as_tuple());
33 assert(c.size() == 1);
34 assert(r->first == 3);
35 assert(r->second == Emplaceable());
36
37 r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
38 assert(c.size() == 2);
39 assert(r->first == 4);
40 assert(r->second == Emplaceable(5, 6));
41
42 r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 5), std::forward_as_tuple(args: 6, args: 7));
43 assert(c.size() == 3);
44 assert(r->first == 5);
45 assert(r->second == Emplaceable(6, 7));
46 }
47 {
48 typedef std::unordered_multimap<int,
49 Emplaceable,
50 std::hash<int>,
51 std::equal_to<int>,
52 min_allocator<std::pair<const int, Emplaceable>>>
53 C;
54 typedef C::iterator R;
55 C c;
56 R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 3), std::forward_as_tuple());
57 assert(c.size() == 1);
58 assert(r->first == 3);
59 assert(r->second == Emplaceable());
60
61 r = c.emplace(std::pair<const int, Emplaceable>(4, Emplaceable(5, 6)));
62 assert(c.size() == 2);
63 assert(r->first == 4);
64 assert(r->second == Emplaceable(5, 6));
65
66 r = c.emplace(std::piecewise_construct, std::forward_as_tuple(args: 5), std::forward_as_tuple(args: 6, args: 7));
67 assert(c.size() == 3);
68 assert(r->first == 5);
69 assert(r->second == Emplaceable(6, 7));
70 }
71
72 return 0;
73}
74

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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