]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/emplace.cc
hashtable.h (_Hashtable<>::emplace, [...]): Add.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / modifiers / emplace.cc
CommitLineData
9b81593b
FD
1// { dg-options "-std=gnu++0x" }
2
3// Copyright (C) 2011 Free Software Foundation, Inc.
4//
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)
9// any later version.
10//
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.
15//
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/>.
19
20// range insert
21
22#include <vector>
23#include <unordered_set>
24#include <testsuite_hooks.h>
25
26class PathPoint
27{
28public:
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; }
35private:
36 char type;
37 std::vector<double> coords;
38};
39
40struct PathPointHasher
41{
42 std::size_t operator() (const PathPoint& __pp) const
43 { return __pp.getType(); }
44};
45
46struct PathPointEqual
47{
48 bool operator() (const PathPoint& __lhs, const PathPoint& __rhs) const
49 { return __lhs.getType() == __rhs.getType(); }
50};
51
52bool test __attribute__((unused)) = true;
53
54void test01()
55{
56 typedef std::unordered_multiset<PathPoint, PathPointHasher,
57 PathPointEqual> Mset;
58 Mset ms;
59
60 std::vector<double> coord1 = { 0.0, 1.0, 2.0 };
61
62 auto it = ms.emplace('a', coord1);
63 VERIFY( ms.size() == 1 );
64 VERIFY( it->getType() == 'a' );
65
66 coord1[0] = 3.0;
67 it = ms.emplace('a', coord1);
68 VERIFY( ms.size() == 2 );
69 VERIFY( it->getType() == 'a' );
70 VERIFY( it->getCoords()[0] == 3.0 );
71
72 it = ms.emplace_hint(ms.begin(), 'b', coord1);
73 VERIFY( it != ms.end() );
74 VERIFY( it->getType() == 'b' );
75 VERIFY( it->getCoords()[0] == 3.0 );
76
77 double *px = &coord1[0];
78 it = ms.emplace('c', std::move(coord1));
79 VERIFY( ms.size() == 4 );
80 VERIFY( it->getType() == 'c' );
81 VERIFY( &(it->getCoords()[0]) == px );
82}
83
84int main()
85{
86 test01();
87 return 0;
88}