]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
5e108459 PC |
2 | |
3 | // 2010-04-30 Paolo Carlini <paolo.carlini@oracle.com> | |
4 | // | |
818ab71a | 5 | // Copyright (C) 2010-2016 Free Software Foundation, Inc. |
5e108459 PC |
6 | // |
7 | // This file is part of the GNU ISO C++ Library. This library is free | |
8 | // software; you can redistribute it and/or modify it under the | |
9 | // terms of the GNU General Public License as published by the | |
10 | // Free Software Foundation; either version 3, or (at your option) | |
11 | // any later version. | |
12 | ||
13 | // This library is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License along | |
19 | // with this library; see the file COPYING3. If not see | |
20 | // <http://www.gnu.org/licenses/>. | |
21 | ||
22 | // Tuple | |
23 | ||
24 | #include <utility> | |
25 | #include <tuple> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | struct type_zero | |
29 | { | |
30 | type_zero() : n_(757) { } | |
31 | ||
32 | type_zero(const type_zero&) = delete; | |
33 | type_zero(type_zero&& other) : n_(other.n_) { } | |
34 | ||
35 | int get() const { return n_; } | |
36 | ||
37 | private: | |
38 | int n_; | |
39 | }; | |
40 | ||
41 | struct type_one | |
42 | { | |
43 | type_one(int n) : n_(n) { } | |
44 | ||
45 | type_one(const type_one&) = delete; | |
46 | type_one(type_one&& other) : n_(other.n_) { } | |
47 | ||
48 | int get() const { return n_; } | |
49 | ||
50 | private: | |
51 | int n_; | |
52 | }; | |
53 | ||
54 | struct type_two | |
55 | { | |
56 | type_two(int n1, int n2) : n1_(n1), n2_(n2) { } | |
57 | ||
58 | type_two(const type_two&) = delete; | |
59 | type_two(type_two&& other) : n1_(other.n1_), n2_(other.n2_) { } | |
60 | ||
61 | int get1() const { return n1_; } | |
62 | int get2() const { return n2_; } | |
63 | ||
64 | private: | |
65 | int n1_, n2_; | |
66 | }; | |
67 | ||
68 | void test01() | |
69 | { | |
bf7818bf | 70 | std::pair<type_one, type_zero> pp0(std::piecewise_construct, |
00e9a944 PC |
71 | std::forward_as_tuple(-3), |
72 | std::forward_as_tuple()); | |
5e108459 PC |
73 | VERIFY( pp0.first.get() == -3 ); |
74 | VERIFY( pp0.second.get() == 757 ); | |
75 | ||
bf7818bf | 76 | std::pair<type_one, type_two> pp1(std::piecewise_construct, |
00e9a944 PC |
77 | std::forward_as_tuple(6), |
78 | std::forward_as_tuple(5, 4)); | |
5e108459 PC |
79 | VERIFY( pp1.first.get() == 6 ); |
80 | VERIFY( pp1.second.get1() == 5 ); | |
81 | VERIFY( pp1.second.get2() == 4 ); | |
82 | ||
bf7818bf | 83 | std::pair<type_two, type_two> pp2(std::piecewise_construct, |
00e9a944 PC |
84 | std::forward_as_tuple(2, 1), |
85 | std::forward_as_tuple(-1, -3)); | |
5e108459 PC |
86 | VERIFY( pp2.first.get1() == 2 ); |
87 | VERIFY( pp2.first.get2() == 1 ); | |
88 | VERIFY( pp2.second.get1() == -1 ); | |
89 | VERIFY( pp2.second.get2() == -3 ); | |
90 | } | |
91 | ||
92 | int main() | |
93 | { | |
94 | test01(); | |
95 | return 0; | |
96 | } |