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 TEST_CONSTEXPR_CXX14
test_tie()25 bool test_tie()
26 {
27 {
28 int i = 42;
29 double f = 1.1;
30 using ExpectT = std::tuple<int&, decltype(std::ignore)&, double&>;
31 auto res = std::tie(i, std::ignore, f);
32 static_assert(std::is_same<ExpectT, decltype(res)>::value, "");
33 assert(&std::get<0>(res) == &i);
34 assert(&std::get<1>(res) == &std::ignore);
35 assert(&std::get<2>(res) == &f);
36
37 #if TEST_STD_VER >= 20
38 res = std::make_tuple(101, nullptr, -1.0);
39 assert(i == 101);
40 assert(f == -1.0);
41 #endif
42 }
43 return true;
44 }
45
main(int,char **)46 int main(int, char**)
47 {
48 test_tie();
49 #if TEST_STD_VER >= 14
50 static_assert(test_tie(), "");
51 #endif
52
53 {
54 int i = 0;
55 std::string s;
56 std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++");
57 assert(i == 42);
58 assert(s == "C++");
59 }
60
61 return 0;
62 }
63