]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/tuple/creation_functions/forward_as_tuple.cc
747b8d3651ae4f67aea61f1449f2023197c03788
1 // { dg-do run { target c++11 } }
3 // 2010-04-30 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2010-2016 Free Software Foundation, Inc.
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)
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.
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/>.
25 #include <type_traits>
26 #include <testsuite_hooks.h>
31 bool test
__attribute__((unused
)) = true;
33 std::forward_as_tuple();
35 VERIFY( std::get
<0>(std::forward_as_tuple(-1)) == -1 );
36 VERIFY( (std::is_same
<decltype(std::forward_as_tuple(-1)),
37 std::tuple
<int&&>>::value
) );
41 const double d1
= 4.0;
42 auto t1
= std::forward_as_tuple(i1
, i2
, d1
);
43 VERIFY( (std::is_same
<decltype(t1
), std::tuple
<const int&,
44 const int&, const double&>>::value
) );
45 VERIFY( std::get
<0>(t1
) == i1
);
46 VERIFY( std::get
<1>(t1
) == i2
);
47 VERIFY( std::get
<2>(t1
) == d1
);
49 typedef const int a_type1
[3];
50 a_type1 a1
= { -1, 1, 2 };
51 auto t2
= std::forward_as_tuple(a1
);
52 VERIFY( (std::is_same
<decltype(t2
), std::tuple
<a_type1
&>>::value
) );
53 VERIFY( std::get
<0>(t2
)[0] == a1
[0] );
54 VERIFY( std::get
<0>(t2
)[1] == a1
[1] );
55 VERIFY( std::get
<0>(t2
)[2] == a1
[2] );
57 typedef int a_type2
[2];
58 a_type2 a2
= { 2, -2 };
60 auto t3
= std::forward_as_tuple(a2
, i4
);
61 VERIFY( (std::is_same
<decltype(t3
), std::tuple
<a_type2
&,
62 volatile int&>>::value
) );
63 VERIFY( std::get
<0>(t3
)[0] == a2
[0] );
64 VERIFY( std::get
<0>(t3
)[1] == a2
[1] );
65 VERIFY( std::get
<1>(t3
) == i4
);