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