]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multimap/modifiers/emplace/1.cc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2012-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/>.
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
;
41 typedef std::multimap
<char, std::vector
<double>> MMap
;
44 std::vector
<double> coord1
= { 0.0, 1.0, 2.0 };
46 auto it
= mm
.emplace('a', coord1
);
47 VERIFY( mm
.size() == 1 );
48 VERIFY( it
->first
== 'a' );
51 it
= mm
.emplace('a', coord1
);
52 VERIFY( mm
.size() == 2 );
53 VERIFY( it
->first
== 'a' );
54 VERIFY( it
->second
[0] == 3.0 );
56 it
= mm
.emplace_hint(mm
.begin(), 'b', coord1
);
57 VERIFY( it
!= mm
.end() );
58 VERIFY( it
->first
== 'b' );
59 VERIFY( it
->second
[0] == 3.0 );
61 double *px
= &coord1
[0];
62 it
= mm
.emplace('c', std::move(coord1
));
63 VERIFY( it
->first
== 'c' );
64 VERIFY( &(it
->second
[0]) == px
);
70 typedef multimap
<char, PathPoint
> Map
;
73 vector
<double> coord1
= { 0.0, 1.0, 2.0 };
75 auto it
= m
.emplace(piecewise_construct
,
76 make_tuple('a'), make_tuple('a', coord1
));
77 VERIFY( m
.size() == 1 );
78 VERIFY( it
->first
== 'a' );
81 it
= m
.emplace(piecewise_construct
,
82 make_tuple('a'), make_tuple( 'b', coord1
));
83 VERIFY( m
.size() == 2 );
84 VERIFY( it
->first
== 'a' );
85 VERIFY( it
->second
.getCoords()[0] == 3.0 );
87 it
= m
.emplace_hint(m
.begin(), piecewise_construct
,
88 make_tuple('b'), make_tuple('c', coord1
));
89 VERIFY( it
!= m
.end() );
90 VERIFY( it
->first
== 'b' );
91 VERIFY( it
->second
.getCoords()[0] == 3.0 );
93 double *px
= &coord1
[0];
94 it
= m
.emplace(piecewise_construct
,
95 make_tuple('c'), make_tuple('d', move(coord1
)));
96 VERIFY( it
->first
== 'c' );
97 VERIFY( &(it
->second
.getCoords()[0]) == px
);