]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/emplace.cc
1 // { dg-options "-std=gnu++11" }
3 // Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
25 #include <unordered_map>
26 #include <testsuite_hooks.h>
31 PathPoint(char t
, const std::vector
<double>& c
)
32 : type(t
), coords(c
) { }
33 PathPoint(char t
, std::vector
<double>&& c
)
34 : type(t
), coords(std::move(c
)) { }
35 char getType() const { return type
; }
36 const std::vector
<double>& getCoords() const { return coords
; }
39 std::vector
<double> coords
;
42 bool test
__attribute__((unused
)) = true;
46 typedef std::unordered_map
<char, std::vector
<double>> Map
;
49 std::vector
<double> coord1
= { 0.0, 1.0, 2.0 };
51 auto ret
= m
.emplace('a', coord1
);
53 VERIFY( m
.size() == 1 );
54 VERIFY( ret
.first
->first
== 'a' );
57 ret
= m
.emplace('a', coord1
);
58 VERIFY( !ret
.second
);
59 VERIFY( m
.size() == 1 );
60 VERIFY( ret
.first
->first
== 'a' );
61 VERIFY( ret
.first
->second
[0] == 0.0 );
63 auto it
= m
.emplace_hint(m
.begin(), 'b', coord1
);
64 VERIFY( it
!= m
.end() );
65 VERIFY( it
->first
== 'b' );
66 VERIFY( it
->second
[0] == 3.0 );
68 double *px
= &coord1
[0];
69 ret
= m
.emplace('c', std::move(coord1
));
71 VERIFY( ret
.first
->first
== 'c' );
72 VERIFY( &(ret
.first
->second
[0]) == px
);
78 typedef unordered_map
<char, PathPoint
> Map
;
81 std::vector
<double> coord1
= { 0.0, 1.0, 2.0 };
83 auto ret
= m
.emplace(piecewise_construct
,
84 make_tuple('a'), make_tuple('a', coord1
));
86 VERIFY( m
.size() == 1 );
87 VERIFY( ret
.first
->first
== 'a' );
90 ret
= m
.emplace(piecewise_construct
,
91 make_tuple('a'), make_tuple( 'b', coord1
));
92 VERIFY( !ret
.second
);
93 VERIFY( m
.size() == 1 );
94 VERIFY( ret
.first
->first
== 'a' );
95 VERIFY( ret
.first
->second
.getCoords()[0] == 0.0 );
97 auto it
= m
.emplace_hint(m
.begin(), piecewise_construct
,
98 make_tuple('b'), make_tuple('c', coord1
));
99 VERIFY( it
!= m
.end() );
100 VERIFY( it
->first
== 'b' );
101 VERIFY( it
->second
.getCoords()[0] == 3.0 );
103 double *px
= &coord1
[0];
104 ret
= m
.emplace(piecewise_construct
,
105 make_tuple('c'), make_tuple('d', move(coord1
)));
106 VERIFY( ret
.second
);
107 VERIFY( ret
.first
->first
== 'c' );
108 VERIFY( &(ret
.first
->second
.getCoords()[0]) == px
);