]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/map/modifiers/emplace/92878_92947.cc
1 // { dg-options "-std=gnu++2a" }
2 // { dg-do run { target c++2a } }
4 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
22 #include <testsuite_hooks.h>
24 struct aggressive_aggregate
32 std::map
<int, aggressive_aggregate
> x
;
33 auto emplaced
= x
.emplace(std::piecewise_construct
,
34 std::tuple(0), std::tuple(1, 2));
35 VERIFY(emplaced
.first
->second
.a
== 1);
36 VERIFY(emplaced
.first
->second
.b
== 2);
37 emplaced
= x
.emplace(std::piecewise_construct
,
38 std::tuple(1), std::tuple(1));
39 VERIFY(emplaced
.first
->second
.a
== 1);
40 VERIFY(emplaced
.first
->second
.b
== 0);
41 emplaced
= x
.emplace(std::piecewise_construct
,
42 std::tuple(2), std::tuple());
43 VERIFY(emplaced
.first
->second
.a
== 0);
44 VERIFY(emplaced
.first
->second
.b
== 0);
47 void test_emplace_hint()
49 std::map
<int, aggressive_aggregate
> x
;
50 auto it
= x
.emplace_hint(x
.begin(),
51 std::piecewise_construct
,
52 std::tuple(3), std::tuple(1, 2));
53 VERIFY(it
->second
.a
== 1);
54 VERIFY(it
->second
.b
== 2);
55 it
= x
.emplace_hint(x
.begin(),
56 std::piecewise_construct
,
57 std::tuple(4), std::tuple(1));
58 VERIFY(it
->second
.a
== 1);
59 VERIFY(it
->second
.b
== 0);
60 it
= x
.emplace_hint(x
.begin(),
61 std::piecewise_construct
,
62 std::tuple(5), std::tuple());
63 VERIFY(it
->second
.a
== 0);
64 VERIFY(it
->second
.b
== 0);
67 void test_try_emplace_rvalue()
69 std::map
<int, aggressive_aggregate
> x
;
70 auto emplaced
= x
.try_emplace(6, 1, 2);
71 VERIFY(emplaced
.first
->second
.a
== 1);
72 VERIFY(emplaced
.first
->second
.b
== 2);
73 emplaced
= x
.try_emplace(7, 1);
74 VERIFY(emplaced
.first
->second
.a
== 1);
75 VERIFY(emplaced
.first
->second
.b
== 0);
76 emplaced
= x
.try_emplace(8);
77 VERIFY(emplaced
.first
->second
.a
== 0);
78 VERIFY(emplaced
.first
->second
.b
== 0);
81 void test_try_emplace_lvalue()
83 std::map
<int, aggressive_aggregate
> x
;
85 auto emplaced
= x
.try_emplace(key
, 1, 2);
86 VERIFY(emplaced
.first
->second
.a
== 1);
87 VERIFY(emplaced
.first
->second
.b
== 2);
89 emplaced
= x
.try_emplace(key
, 1);
90 VERIFY(emplaced
.first
->second
.a
== 1);
91 VERIFY(emplaced
.first
->second
.b
== 0);
93 emplaced
= x
.try_emplace(key
);
94 VERIFY(emplaced
.first
->second
.a
== 0);
95 VERIFY(emplaced
.first
->second
.b
== 0);
98 void test_try_emplace_hint_rvalue()
100 std::map
<int, aggressive_aggregate
> x
;
101 auto it
= x
.try_emplace(x
.begin(), 12, 1, 2);
102 VERIFY(it
->second
.a
== 1);
103 VERIFY(it
->second
.b
== 2);
104 it
= x
.try_emplace(x
.begin(), 13, 1);
105 VERIFY(it
->second
.a
== 1);
106 VERIFY(it
->second
.b
== 0);
107 it
= x
.try_emplace(x
.begin(), 14);
108 VERIFY(it
->second
.a
== 0);
109 VERIFY(it
->second
.b
== 0);
112 void test_try_emplace_hint_lvalue()
114 std::map
<int, aggressive_aggregate
> x
;
116 auto it
= x
.try_emplace(x
.begin(), key
, 1, 2);
117 VERIFY(it
->second
.a
== 1);
118 VERIFY(it
->second
.b
== 2);
120 it
= x
.try_emplace(x
.begin(), key
, 1);
121 VERIFY(it
->second
.a
== 1);
122 VERIFY(it
->second
.b
== 0);
124 it
= x
.try_emplace(x
.begin(), key
);
125 VERIFY(it
->second
.a
== 0);
126 VERIFY(it
->second
.b
== 0);
133 test_try_emplace_rvalue();
134 test_try_emplace_lvalue();
135 test_try_emplace_hint_rvalue();
136 test_try_emplace_hint_lvalue();