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