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 <size_t I, class... Types> 15 // const typename tuple_element<I, tuple<Types...> >::type&& 16 // get(const tuple<Types...>&& t); 17 18 // UNSUPPORTED: c++98, c++03 19 20 #include <tuple> 21 #include <utility> 22 #include <string> 23 #include <type_traits> 24 #include <cassert> 25 26 #include "test_macros.h" 27 28 int main() 29 { 30 { 31 typedef std::tuple<int> T; 32 const T t(3); 33 static_assert(std::is_same<const int&&, decltype(std::get<0>(std::move(t)))>::value, ""); 34 static_assert(noexcept(std::get<0>(std::move(t))), ""); 35 const int&& i = std::get<0>(std::move(t)); 36 assert(i == 3); 37 } 38 39 { 40 typedef std::tuple<std::string, int> T; 41 const T t("high", 5); 42 static_assert(std::is_same<const std::string&&, decltype(std::get<0>(std::move(t)))>::value, ""); 43 static_assert(noexcept(std::get<0>(std::move(t))), ""); 44 static_assert(std::is_same<const int&&, decltype(std::get<1>(std::move(t)))>::value, ""); 45 static_assert(noexcept(std::get<1>(std::move(t))), ""); 46 const std::string&& s = std::get<0>(std::move(t)); 47 const int&& i = std::get<1>(std::move(t)); 48 assert(s == "high"); 49 assert(i == 5); 50 } 51 52 { 53 int x = 42; 54 int const y = 43; 55 std::tuple<int&, int const&> const p(x, y); 56 static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, ""); 57 static_assert(noexcept(std::get<0>(std::move(p))), ""); 58 static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, ""); 59 static_assert(noexcept(std::get<1>(std::move(p))), ""); 60 } 61 62 { 63 int x = 42; 64 int const y = 43; 65 std::tuple<int&&, int const&&> const p(std::move(x), std::move(y)); 66 static_assert(std::is_same<int&&, decltype(std::get<0>(std::move(p)))>::value, ""); 67 static_assert(noexcept(std::get<0>(std::move(p))), ""); 68 static_assert(std::is_same<int const&&, decltype(std::get<1>(std::move(p)))>::value, ""); 69 static_assert(noexcept(std::get<1>(std::move(p))), ""); 70 } 71 72 #if TEST_STD_VER > 11 73 { 74 typedef std::tuple<double, int> T; 75 constexpr const T t(2.718, 5); 76 static_assert(std::get<0>(std::move(t)) == 2.718, ""); 77 static_assert(std::get<1>(std::move(t)) == 5, ""); 78 } 79 #endif 80 } 81