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 <tuple>
21 #include <vector>
22 #include <map>
23 #include <testsuite_hooks.h>
24 
25 class PathPoint
26 {
27 public:
PathPoint(char t,const std::vector<double> & c)28   PathPoint(char t, const std::vector<double>& c)
29   : type(t), coords(c) { }
PathPoint(char t,std::vector<double> && c)30   PathPoint(char t, std::vector<double>&& c)
31   : type(t), coords(std::move(c)) { }
getType() const32   char getType() const { return type; }
getCoords() const33   const std::vector<double>& getCoords() const { return coords; }
34 private:
35   char type;
36   std::vector<double> coords;
37 };
38 
test01()39 void test01()
40 {
41   typedef std::multimap<char, std::vector<double>> MMap;
42   MMap mm;
43 
44   std::vector<double> coord1 = { 0.0, 1.0, 2.0 };
45 
46   auto it = mm.emplace('a', coord1);
47   VERIFY( mm.size() == 1 );
48   VERIFY( it->first == 'a' );
49 
50   coord1[0] = 3.0;
51   it = mm.emplace('a', coord1);
52   VERIFY( mm.size() == 2 );
53   VERIFY( it->first == 'a' );
54   VERIFY( it->second[0] == 3.0 );
55 
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 );
60 
61   double *px = &coord1[0];
62   it = mm.emplace('c', std::move(coord1));
63   VERIFY( it->first == 'c' );
64   VERIFY( &(it->second[0]) == px );
65 }
66 
test02()67 void test02()
68 {
69   using namespace std;
70   typedef multimap<char, PathPoint> Map;
71   Map m;
72 
73   vector<double> coord1 = { 0.0, 1.0, 2.0 };
74 
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' );
79 
80   coord1[0] = 3.0;
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 );
86 
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 );
92 
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 );
98 }
99 
100 
main()101 int main()
102 {
103   test01();
104   test02();
105   return 0;
106 }
107