1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <tuple>
11 
12 // template <class... Types> class tuple;
13 
14 // template<class... Types>
15 //   tuple<Types&...> tie(Types&... t);
16 
17 // UNSUPPORTED: c++98, c++03
18 
19 #include <tuple>
20 #include <string>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 
25 #if TEST_STD_VER > 11
test_tie_constexpr()26 constexpr bool test_tie_constexpr() {
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         // FIXME: If/when tuple gets constexpr assignment
37         //res = std::make_tuple(101, nullptr, -1.0);
38     }
39     return true;
40 }
41 #endif
42 
main()43 int main()
44 {
45     {
46         int i = 0;
47         std::string s;
48         std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++");
49         assert(i == 42);
50         assert(s == "C++");
51     }
52 #if TEST_STD_VER > 11
53     {
54         static constexpr int i = 42;
55         static constexpr double f = 1.1;
56         constexpr std::tuple<const int &, const double &> t = std::tie(i, f);
57         static_assert ( std::get<0>(t) == 42, "" );
58         static_assert ( std::get<1>(t) == 1.1, "" );
59     }
60     {
61         static_assert(test_tie_constexpr(), "");
62     }
63 #endif
64 }
65