]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
55826ab6 | 2 | |
8d9254fc | 3 | // Copyright (C) 2012-2020 Free Software Foundation, Inc. |
55826ab6 FD |
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 | #include <vector> | |
21 | #include <set> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | class PathPoint | |
25 | { | |
26 | public: | |
27 | PathPoint(char t, const std::vector<double>& c) | |
28 | : type(t), coords(c) { } | |
29 | PathPoint(char t, std::vector<double>&& c) | |
30 | : type(t), coords(std::move(c)) { } | |
31 | char getType() const { return type; } | |
32 | const std::vector<double>& getCoords() const { return coords; } | |
33 | private: | |
34 | char type; | |
35 | std::vector<double> coords; | |
36 | }; | |
37 | ||
38 | struct PathPointLess | |
39 | { | |
40 | bool operator() (const PathPoint& __lhs, const PathPoint& __rhs) const | |
41 | { return __lhs.getType() < __rhs.getType(); } | |
42 | }; | |
43 | ||
55826ab6 FD |
44 | void test01() |
45 | { | |
46 | typedef std::set<PathPoint, PathPointLess> Set; | |
47 | Set s; | |
48 | ||
49 | std::vector<double> coord1 = { 0.0, 1.0, 2.0 }; | |
50 | ||
51 | auto ret = s.emplace('a', coord1); | |
52 | VERIFY( ret.second ); | |
53 | VERIFY( s.size() == 1 ); | |
54 | VERIFY( ret.first->getType() == 'a' ); | |
55 | ||
56 | coord1[0] = 3.0; | |
57 | ret = s.emplace('a', coord1); | |
58 | VERIFY( !ret.second ); | |
59 | VERIFY( s.size() == 1 ); | |
60 | VERIFY( ret.first->getType() == 'a' ); | |
61 | VERIFY( ret.first->getCoords()[0] == 0.0 ); | |
62 | ||
63 | auto it = s.emplace_hint(s.begin(), 'b', coord1); | |
64 | VERIFY( it != s.end() ); | |
65 | VERIFY( it->getType() == 'b' ); | |
66 | VERIFY( it->getCoords()[0] == 3.0 ); | |
67 | ||
68 | double *px = &coord1[0]; | |
69 | ret = s.emplace('c', std::move(coord1)); | |
70 | VERIFY( ret.second ); | |
71 | VERIFY( ret.first->getType() == 'c' ); | |
72 | VERIFY( &(ret.first->getCoords()[0]) == px ); | |
73 | } | |
74 | ||
75 | int main() | |
76 | { | |
77 | test01(); | |
78 | return 0; | |
79 | } |