| 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 | // <tuple> |
| 10 | |
| 11 | // template <class... Types> class tuple; |
| 12 | |
| 13 | // template <class U1, class U2> |
| 14 | // tuple& operator=(const pair<U1, U2>& u); |
| 15 | |
| 16 | // UNSUPPORTED: c++03 |
| 17 | |
| 18 | #include <cassert> |
| 19 | #include <memory> |
| 20 | #include <tuple> |
| 21 | #include <type_traits> |
| 22 | #include <utility> |
| 23 | |
| 24 | struct NothrowCopyAssignable { |
| 25 | NothrowCopyAssignable(NothrowCopyAssignable const&) = delete; |
| 26 | NothrowCopyAssignable& operator=(NothrowCopyAssignable const&) noexcept { return *this; } |
| 27 | }; |
| 28 | struct PotentiallyThrowingCopyAssignable { |
| 29 | PotentiallyThrowingCopyAssignable(PotentiallyThrowingCopyAssignable const&) = delete; |
| 30 | PotentiallyThrowingCopyAssignable& operator=(PotentiallyThrowingCopyAssignable const&) { return *this; } |
| 31 | }; |
| 32 | |
| 33 | #include "test_macros.h" |
| 34 | |
| 35 | TEST_CONSTEXPR_CXX20 |
| 36 | bool test() |
| 37 | { |
| 38 | { |
| 39 | typedef std::pair<long, char> T0; |
| 40 | typedef std::tuple<long long, short> T1; |
| 41 | T0 t0(2, 'a'); |
| 42 | T1 t1; |
| 43 | t1 = t0; |
| 44 | assert(std::get<0>(t1) == 2); |
| 45 | assert(std::get<1>(t1) == short('a')); |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | int main(int, char**) |
| 51 | { |
| 52 | test(); |
| 53 | #if TEST_STD_VER >= 20 |
| 54 | static_assert(test()); |
| 55 | #endif |
| 56 | |
| 57 | { |
| 58 | // test that the implicitly generated copy assignment operator |
| 59 | // is properly deleted |
| 60 | using T = std::tuple<int, int>; |
| 61 | using P = std::tuple<std::unique_ptr<int>, std::unique_ptr<int>>; |
| 62 | static_assert(!std::is_assignable<T&, const P &>::value, "" ); |
| 63 | } |
| 64 | { |
| 65 | typedef std::tuple<NothrowCopyAssignable, long> Tuple; |
| 66 | typedef std::pair<NothrowCopyAssignable, int> Pair; |
| 67 | static_assert(std::is_nothrow_assignable<Tuple&, Pair const&>::value, "" ); |
| 68 | static_assert(std::is_nothrow_assignable<Tuple&, Pair&>::value, "" ); |
| 69 | static_assert(std::is_nothrow_assignable<Tuple&, Pair const&&>::value, "" ); |
| 70 | } |
| 71 | { |
| 72 | typedef std::tuple<PotentiallyThrowingCopyAssignable, long> Tuple; |
| 73 | typedef std::pair<PotentiallyThrowingCopyAssignable, int> Pair; |
| 74 | static_assert(std::is_assignable<Tuple&, Pair const&>::value, "" ); |
| 75 | static_assert(!std::is_nothrow_assignable<Tuple&, Pair const&>::value, "" ); |
| 76 | |
| 77 | static_assert(std::is_assignable<Tuple&, Pair&>::value, "" ); |
| 78 | static_assert(!std::is_nothrow_assignable<Tuple&, Pair&>::value, "" ); |
| 79 | |
| 80 | static_assert(std::is_assignable<Tuple&, Pair const&&>::value, "" ); |
| 81 | static_assert(!std::is_nothrow_assignable<Tuple&, Pair const&&>::value, "" ); |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |