]>
Commit | Line | Data |
---|---|---|
8868286e | 1 | // { dg-options "-std=gnu++11" } |
bd142bda | 2 | |
f1717362 | 3 | // Copyright (C) 2011-2016 Free Software Foundation, Inc. |
bd142bda | 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 <tuple> | |
23 | #include <vector> | |
24 | #include <unordered_map> | |
25 | #include <testsuite_hooks.h> | |
26 | ||
27 | class PathPoint | |
28 | { | |
29 | public: | |
30 | PathPoint(char t, const std::vector<double>& c) | |
31 | : type(t), coords(c) { } | |
32 | PathPoint(char t, std::vector<double>&& c) | |
33 | : type(t), coords(std::move(c)) { } | |
34 | char getType() const { return type; } | |
35 | const std::vector<double>& getCoords() const { return coords; } | |
36 | private: | |
37 | char type; | |
38 | std::vector<double> coords; | |
39 | }; | |
40 | ||
41 | bool test __attribute__((unused)) = true; | |
42 | ||
43 | void test01() | |
44 | { | |
45 | typedef std::unordered_multimap<char, std::vector<double>> MMap; | |
46 | MMap mm; | |
47 | ||
48 | std::vector<double> coord1 = { 0.0, 1.0, 2.0 }; | |
49 | ||
50 | auto it = mm.emplace('a', coord1); | |
51 | VERIFY( mm.size() == 1 ); | |
52 | VERIFY( it->first == 'a' ); | |
53 | ||
54 | coord1[0] = 3.0; | |
55 | it = mm.emplace('a', coord1); | |
56 | VERIFY( mm.size() == 2 ); | |
57 | VERIFY( it->first == 'a' ); | |
58 | VERIFY( it->second[0] == 3.0 ); | |
59 | ||
60 | it = mm.emplace_hint(mm.begin(), 'b', coord1); | |
61 | VERIFY( it != mm.end() ); | |
62 | VERIFY( it->first == 'b' ); | |
63 | VERIFY( it->second[0] == 3.0 ); | |
64 | ||
65 | double *px = &coord1[0]; | |
66 | it = mm.emplace('c', std::move(coord1)); | |
67 | VERIFY( it->first == 'c' ); | |
68 | VERIFY( &(it->second[0]) == px ); | |
69 | } | |
70 | ||
71 | void test02() | |
72 | { | |
73 | using namespace std; | |
74 | typedef unordered_multimap<char, PathPoint> Map; | |
75 | Map m; | |
76 | ||
77 | std::vector<double> coord1 = { 0.0, 1.0, 2.0 }; | |
78 | ||
79 | auto it = m.emplace(piecewise_construct, | |
80 | make_tuple('a'), make_tuple('a', coord1)); | |
81 | VERIFY( m.size() == 1 ); | |
82 | VERIFY( it->first == 'a' ); | |
83 | ||
84 | coord1[0] = 3.0; | |
85 | it = m.emplace(piecewise_construct, | |
86 | make_tuple('a'), make_tuple( 'b', coord1)); | |
87 | VERIFY( m.size() == 2 ); | |
88 | VERIFY( it->first == 'a' ); | |
89 | VERIFY( it->second.getCoords()[0] == 3.0 ); | |
90 | ||
91 | it = m.emplace_hint(m.begin(), piecewise_construct, | |
92 | make_tuple('b'), make_tuple('c', coord1)); | |
93 | VERIFY( it != m.end() ); | |
94 | VERIFY( it->first == 'b' ); | |
95 | VERIFY( it->second.getCoords()[0] == 3.0 ); | |
96 | ||
97 | double *px = &coord1[0]; | |
98 | it = m.emplace(piecewise_construct, | |
99 | make_tuple('c'), make_tuple('d', move(coord1))); | |
100 | VERIFY( it->first == 'c' ); | |
101 | VERIFY( &(it->second.getCoords()[0]) == px ); | |
102 | } | |
103 | ||
104 | ||
105 | int main() | |
106 | { | |
107 | test01(); | |
108 | test02(); | |
109 | return 0; | |
110 | } |