]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/emplace.cc
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2011-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 <unordered_set>
24 #include <testsuite_hooks.h>
29 PathPoint(char t
, const std::vector
<double>& c
)
30 : type(t
), coords(c
) { }
31 PathPoint(char t
, std::vector
<double>&& c
)
32 : type(t
), coords(std::move(c
)) { }
33 char getType() const { return type
; }
34 const std::vector
<double>& getCoords() const { return coords
; }
37 std::vector
<double> coords
;
40 struct PathPointHasher
42 std::size_t operator() (const PathPoint
& __pp
) const
43 { return __pp
.getType(); }
48 bool operator() (const PathPoint
& __lhs
, const PathPoint
& __rhs
) const
49 { return __lhs
.getType() == __rhs
.getType(); }
52 bool test
__attribute__((unused
)) = true;
56 typedef std::unordered_set
<PathPoint
, PathPointHasher
, PathPointEqual
> Set
;
59 std::vector
<double> coord1
= { 0.0, 1.0, 2.0 };
61 auto ret
= s
.emplace('a', coord1
);
63 VERIFY( s
.size() == 1 );
64 VERIFY( ret
.first
->getType() == 'a' );
67 ret
= s
.emplace('a', coord1
);
68 VERIFY( !ret
.second
);
69 VERIFY( s
.size() == 1 );
70 VERIFY( ret
.first
->getType() == 'a' );
71 VERIFY( ret
.first
->getCoords()[0] == 0.0 );
73 auto it
= s
.emplace_hint(s
.begin(), 'b', coord1
);
74 VERIFY( it
!= s
.end() );
75 VERIFY( it
->getType() == 'b' );
76 VERIFY( it
->getCoords()[0] == 3.0 );
78 double *px
= &coord1
[0];
79 ret
= s
.emplace('c', std::move(coord1
));
81 VERIFY( ret
.first
->getType() == 'c' );
82 VERIFY( &(ret
.first
->getCoords()[0]) == px
);