]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multimap/modifiers/emplace/1.cc
cf3e95e326e6be3eafa3f132d9a0889e9f29bafd
1 // { dg-options "-std=c++11" }
3 // Copyright (C) 2012-2013 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/>.
23 #include <testsuite_hooks.h>
28 PathPoint(char t
, const std::vector
<double>& c
)
29 : type(t
), coords(c
) { }
30 PathPoint(char t
, std::vector
<double>&& c
)
31 : type(t
), coords(std::move(c
)) { }
32 char getType() const { return type
; }
33 const std::vector
<double>& getCoords() const { return coords
; }
36 std::vector
<double> coords
;
39 bool test
__attribute__((unused
)) = true;
43 typedef std::multimap
<char, std::vector
<double>> MMap
;
46 std::vector
<double> coord1
= { 0.0, 1.0, 2.0 };
48 auto it
= mm
.emplace('a', coord1
);
49 VERIFY( mm
.size() == 1 );
50 VERIFY( it
->first
== 'a' );
53 it
= mm
.emplace('a', coord1
);
54 VERIFY( mm
.size() == 2 );
55 VERIFY( it
->first
== 'a' );
56 VERIFY( it
->second
[0] == 3.0 );
58 it
= mm
.emplace_hint(mm
.begin(), 'b', coord1
);
59 VERIFY( it
!= mm
.end() );
60 VERIFY( it
->first
== 'b' );
61 VERIFY( it
->second
[0] == 3.0 );
63 double *px
= &coord1
[0];
64 it
= mm
.emplace('c', std::move(coord1
));
65 VERIFY( it
->first
== 'c' );
66 VERIFY( &(it
->second
[0]) == px
);
72 typedef multimap
<char, PathPoint
> Map
;
75 vector
<double> coord1
= { 0.0, 1.0, 2.0 };
77 auto it
= m
.emplace(piecewise_construct
,
78 make_tuple('a'), make_tuple('a', coord1
));
79 VERIFY( m
.size() == 1 );
80 VERIFY( it
->first
== 'a' );
83 it
= m
.emplace(piecewise_construct
,
84 make_tuple('a'), make_tuple( 'b', coord1
));
85 VERIFY( m
.size() == 2 );
86 VERIFY( it
->first
== 'a' );
87 VERIFY( it
->second
.getCoords()[0] == 3.0 );
89 it
= m
.emplace_hint(m
.begin(), piecewise_construct
,
90 make_tuple('b'), make_tuple('c', coord1
));
91 VERIFY( it
!= m
.end() );
92 VERIFY( it
->first
== 'b' );
93 VERIFY( it
->second
.getCoords()[0] == 3.0 );
95 double *px
= &coord1
[0];
96 it
= m
.emplace(piecewise_construct
,
97 make_tuple('c'), make_tuple('d', move(coord1
)));
98 VERIFY( it
->first
== 'c' );
99 VERIFY( &(it
->second
.getCoords()[0]) == px
);