]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/tuple/apply/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / tuple / apply / 1.cc
CommitLineData
85ec4feb 1// Copyright (C) 2014-2018 Free Software Foundation, Inc.
3e9f67e6
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-options "-std=gnu++17" }
19
20#include <tuple>
21#include <testsuite_hooks.h>
22
23#if __cpp_lib_apply < 201603
24# error "__cpp_lib_apply < 201603"
25#endif
26
27void
28test01()
29{
30 auto t = std::make_tuple(1, '2', 3.0);
31 std::apply( [&](int& i, char& c, double& d) {
32 VERIFY(&i == &std::get<int>(t));
33 VERIFY(&c == &std::get<char>(t));
34 VERIFY(&d == &std::get<double>(t));
35 }, t);
36}
37
38constexpr int func(int i, int j) { return i + j; }
39
40void
41test02()
42{
43 constexpr auto t = std::make_tuple(1, 2);
44 constexpr int i = std::apply(func, t);
45 VERIFY( i == 3 );
46}
47
48struct F
49{
50 int f(int i, int j) const { return i + j; }
51};
52
53void
54test03()
55{
56 auto t = std::make_tuple(F{}, 1, 2);
57 int r = std::apply(&F::f, t);
58 VERIFY( r == 3 );
59}
60
61int
62main()
63{
64 test01();
65 test02();
66 test03();
67}