1// { dg-options "-std=gnu++11" } 2 3// 2010-04-30 Paolo Carlini <paolo.carlini@oracle.com> 4// 5// Copyright (C) 2010-2015 Free Software Foundation, Inc. 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 28struct 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 37private: 38 int n_; 39}; 40 41struct 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 50private: 51 int n_; 52}; 53 54struct 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 64private: 65 int n1_, n2_; 66}; 67 68void test01() 69{ 70 bool test __attribute__((unused)) = true; 71 72 std::pair<type_one, type_zero> pp0(std::piecewise_construct_t(), 73 std::forward_as_tuple(-3), 74 std::forward_as_tuple()); 75 VERIFY( pp0.first.get() == -3 ); 76 VERIFY( pp0.second.get() == 757 ); 77 78 std::pair<type_one, type_two> pp1(std::piecewise_construct_t(), 79 std::forward_as_tuple(6), 80 std::forward_as_tuple(5, 4)); 81 VERIFY( pp1.first.get() == 6 ); 82 VERIFY( pp1.second.get1() == 5 ); 83 VERIFY( pp1.second.get2() == 4 ); 84 85 std::pair<type_two, type_two> pp2(std::piecewise_construct_t(), 86 std::forward_as_tuple(2, 1), 87 std::forward_as_tuple(-1, -3)); 88 VERIFY( pp2.first.get1() == 2 ); 89 VERIFY( pp2.first.get2() == 1 ); 90 VERIFY( pp2.second.get1() == -1 ); 91 VERIFY( pp2.second.get2() == -3 ); 92} 93 94int main() 95{ 96 test01(); 97 return 0; 98} 99