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 // <utility> 10 11 // template <class T1, class T2> struct pair 12 13 // template<size_t I, class T1, class T2> 14 // const typename tuple_element<I, std::pair<T1, T2> >::type&& 15 // get(const pair<T1, T2>&&); 16 17 // UNSUPPORTED: c++03 18 19 #include <utility> 20 #include <memory> 21 #include <type_traits> 22 #include <cassert> 23 24 #include "test_macros.h" 25 26 int main(int, char**) 27 { 28 { 29 typedef std::pair<std::unique_ptr<int>, short> P; 30 const P p(std::unique_ptr<int>(new int(3)), static_cast<short>(4)); 31 static_assert(std::is_same<const std::unique_ptr<int>&&, decltype(std::get<0>(std::move(p)))>::value, ""); 32 static_assert(noexcept(std::get<0>(std::move(p))), ""); 33 const std::unique_ptr<int>&& ptr = std::get<0>(std::move(p)); 34 assert(*ptr == 3); 35 } 36 37 { 38 int x = 42; 39 int const y = 43; 40 std::pair<int&, int const&> const p(x, y); 41 static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, ""); 42 static_assert(noexcept(std::get<0>(std::move(p))), ""); 43 static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, ""); 44 static_assert(noexcept(std::get<1>(std::move(p))), ""); 45 } 46 47 { 48 int x = 42; 49 int const y = 43; 50 std::pair<int&&, int const&&> const p(std::move(x), std::move(y)); 51 static_assert(std::is_same<int&&, decltype(std::get<0>(std::move(p)))>::value, ""); 52 static_assert(noexcept(std::get<0>(std::move(p))), ""); 53 static_assert(std::is_same<int const&&, decltype(std::get<1>(std::move(p)))>::value, ""); 54 static_assert(noexcept(std::get<1>(std::move(p))), ""); 55 } 56 57 #if TEST_STD_VER > 11 58 { 59 typedef std::pair<int, short> P; 60 constexpr const P p1(3, static_cast<short>(4)); 61 static_assert(std::get<0>(std::move(p1)) == 3, ""); 62 static_assert(std::get<1>(std::move(p1)) == 4, ""); 63 } 64 #endif 65 66 return 0; 67 } 68