]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2014-2022 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 | ||
6458742a | 18 | // { dg-do run { target c++17 } } |
3e9f67e6 JW |
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 | ||
27 | void | |
28 | test01() | |
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 | ||
38 | constexpr int func(int i, int j) { return i + j; } | |
39 | ||
40 | void | |
41 | test02() | |
42 | { | |
43 | constexpr auto t = std::make_tuple(1, 2); | |
44 | constexpr int i = std::apply(func, t); | |
45 | VERIFY( i == 3 ); | |
46 | } | |
47 | ||
48 | struct F | |
49 | { | |
50 | int f(int i, int j) const { return i + j; } | |
51 | }; | |
52 | ||
53 | void | |
54 | test03() | |
55 | { | |
56 | auto t = std::make_tuple(F{}, 1, 2); | |
57 | int r = std::apply(&F::f, t); | |
58 | VERIFY( r == 3 ); | |
59 | } | |
60 | ||
61 | int | |
62 | main() | |
63 | { | |
64 | test01(); | |
65 | test02(); | |
66 | test03(); | |
67 | } |