]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/tuple/creation_functions/forward_as_tuple.cc
1 // { dg-do run { target c++11 } }
3 // 2010-04-30 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2010-2024 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 std::forward_as_tuple();
33 VERIFY( std::get
<0>(std::forward_as_tuple(-1)) == -1 );
34 VERIFY( (std::is_same
<decltype(std::forward_as_tuple(-1)),
35 std::tuple
<int&&>>::value
) );
39 const double d1
= 4.0;
40 auto t1
= std::forward_as_tuple(i1
, i2
, d1
);
41 VERIFY( (std::is_same
<decltype(t1
), std::tuple
<const int&,
42 const int&, const double&>>::value
) );
43 VERIFY( std::get
<0>(t1
) == i1
);
44 VERIFY( std::get
<1>(t1
) == i2
);
45 VERIFY( std::get
<2>(t1
) == d1
);
47 typedef const int a_type1
[3];
48 a_type1 a1
= { -1, 1, 2 };
49 auto t2
= std::forward_as_tuple(a1
);
50 VERIFY( (std::is_same
<decltype(t2
), std::tuple
<a_type1
&>>::value
) );
51 VERIFY( std::get
<0>(t2
)[0] == a1
[0] );
52 VERIFY( std::get
<0>(t2
)[1] == a1
[1] );
53 VERIFY( std::get
<0>(t2
)[2] == a1
[2] );
55 typedef int a_type2
[2];
56 a_type2 a2
= { 2, -2 };
58 auto t3
= std::forward_as_tuple(a2
, i4
);
59 VERIFY( (std::is_same
<decltype(t3
), std::tuple
<a_type2
&,
60 volatile int&>>::value
) );
61 VERIFY( std::get
<0>(t3
)[0] == a2
[0] );
62 VERIFY( std::get
<0>(t3
)[1] == a2
[1] );
63 VERIFY( std::get
<1>(t3
) == i4
);