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<Types&...> tie(Types&... t);
15
16 // UNSUPPORTED: c++03
17
18 #include <tuple>
19 #include <string>
20 #include <cassert>
21
22 #include "test_macros.h"
23
24 #if TEST_STD_VER > 11
test_tie_constexpr()25 constexpr bool test_tie_constexpr() {
26 {
27 int i = 42;
28 double f = 1.1;
29 using ExpectT = std::tuple<int&, decltype(std::ignore)&, double&>;
30 auto res = std::tie(i, std::ignore, f);
31 static_assert(std::is_same<ExpectT, decltype(res)>::value, "");
32 assert(&std::get<0>(res) == &i);
33 assert(&std::get<1>(res) == &std::ignore);
34 assert(&std::get<2>(res) == &f);
35 // FIXME: If/when tuple gets constexpr assignment
36 //res = std::make_tuple(101, nullptr, -1.0);
37 }
38 return true;
39 }
40 #endif
41
main(int,char **)42 int main(int, char**)
43 {
44 {
45 int i = 0;
46 std::string s;
47 std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++");
48 assert(i == 42);
49 assert(s == "C++");
50 }
51 #if TEST_STD_VER > 11
52 {
53 static constexpr int i = 42;
54 static constexpr double f = 1.1;
55 constexpr std::tuple<const int &, const double &> t = std::tie(i, f);
56 static_assert ( std::get<0>(t) == 42, "" );
57 static_assert ( std::get<1>(t) == 1.1, "" );
58 }
59 {
60 static_assert(test_tie_constexpr(), "");
61 }
62 #endif
63
64 return 0;
65 }
66