xref: /llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.creation/make_tuple.pass.cpp (revision 06e2b737aa0347b42e8bf37cb00a053eab0a9393)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <tuple>
10 
11 // template <class... Types> class tuple;
12 
13 // template<class... Types>
14 //   tuple<VTypes...> make_tuple(Types&&... t);
15 
16 // UNSUPPORTED: c++03
17 
18 #include <tuple>
19 #include <functional>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 
24 TEST_CONSTEXPR_CXX20
test()25 bool test()
26 {
27     int i = 0;
28     float j = 0;
29     std::tuple<int, int&, float&> t =
30         std::make_tuple(1, std::ref(i), std::ref(j));
31     assert(std::get<0>(t) == 1);
32     assert(std::get<1>(t) == 0);
33     assert(std::get<2>(t) == 0);
34     i = 2;
35     j = 3.5;
36     assert(std::get<0>(t) == 1);
37     assert(std::get<1>(t) == 2);
38     assert(std::get<2>(t) == 3.5);
39     std::get<1>(t) = 0;
40     std::get<2>(t) = 0;
41     assert(i == 0);
42     assert(j == 0);
43 
44     return true;
45 }
46 
main(int,char **)47 int main(int, char**)
48 {
49     test();
50 #if TEST_STD_VER >= 20
51     static_assert(test());
52 #endif
53 
54 #if TEST_STD_VER > 11
55     {
56         constexpr auto t1 = std::make_tuple(0, 1, 3.14);
57         constexpr int i1 = std::get<1>(t1);
58         constexpr double d1 = std::get<2>(t1);
59         static_assert (i1 == 1, "" );
60         static_assert (d1 == 3.14, "" );
61     }
62 #endif
63 
64     return 0;
65 }
66