| 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 && !stdlib=libc++ |
| 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 | #if TEST_STD_VER >= 11 |
| 30 | typedef std::pair<std::unique_ptr<int>, short> P; |
| 31 | const P p(std::unique_ptr<int>(new int(3)), static_cast<short>(4)); |
| 32 | static_assert(std::is_same<const std::unique_ptr<int>&&, decltype(std::get<0>(std::move(p)))>::value, "" ); |
| 33 | static_assert(noexcept(std::get<0>(std::move(p))), "" ); |
| 34 | const std::unique_ptr<int>&& ptr = std::get<0>(std::move(p)); |
| 35 | assert(*ptr == 3); |
| 36 | #endif |
| 37 | } |
| 38 | |
| 39 | { |
| 40 | int x = 42; |
| 41 | int const y = 43; |
| 42 | std::pair<int&, int const&> const p(x, y); |
| 43 | static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, "" ); |
| 44 | static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "" ); |
| 45 | #if TEST_STD_VER >= 11 |
| 46 | static_assert(noexcept(std::get<0>(std::move(p))), "" ); |
| 47 | static_assert(noexcept(std::get<1>(std::move(p))), "" ); |
| 48 | #endif |
| 49 | } |
| 50 | |
| 51 | { |
| 52 | #if TEST_STD_VER >= 11 |
| 53 | int x = 42; |
| 54 | int const y = 43; |
| 55 | std::pair<int&&, int const&&> const p(std::move(x), std::move(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 | #endif |
| 61 | } |
| 62 | |
| 63 | #if TEST_STD_VER > 11 |
| 64 | { |
| 65 | typedef std::pair<int, short> P; |
| 66 | constexpr const P p1(3, static_cast<short>(4)); |
| 67 | static_assert(std::get<0>(std::move(p1)) == 3, "" ); |
| 68 | static_assert(std::get<1>(std::move(p1)) == 4, "" ); |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |