15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // <tuple>
105a83710eSEric Fiselier
115a83710eSEric Fiselier // template <class... Types> class tuple;
125a83710eSEric Fiselier
135a83710eSEric Fiselier // template <class U1, class U2>
145a83710eSEric Fiselier // tuple& operator=(const pair<U1, U2>& u);
155a83710eSEric Fiselier
1631cbe0f2SLouis Dionne // UNSUPPORTED: c++03
170a52cd79SEric Fiselier
185a83710eSEric Fiselier #include <cassert>
19a0839b14SLouis Dionne #include <memory>
20a0839b14SLouis Dionne #include <tuple>
21a0839b14SLouis Dionne #include <type_traits>
22a0839b14SLouis Dionne #include <utility>
23a0839b14SLouis Dionne
24a0839b14SLouis Dionne struct NothrowCopyAssignable {
25*e39095a3SLouis Dionne NothrowCopyAssignable(NothrowCopyAssignable const&) = delete;
operator =NothrowCopyAssignable26a0839b14SLouis Dionne NothrowCopyAssignable& operator=(NothrowCopyAssignable const&) noexcept { return *this; }
27a0839b14SLouis Dionne };
28a0839b14SLouis Dionne struct PotentiallyThrowingCopyAssignable {
29*e39095a3SLouis Dionne PotentiallyThrowingCopyAssignable(PotentiallyThrowingCopyAssignable const&) = delete;
operator =PotentiallyThrowingCopyAssignable30a0839b14SLouis Dionne PotentiallyThrowingCopyAssignable& operator=(PotentiallyThrowingCopyAssignable const&) { return *this; }
31a0839b14SLouis Dionne };
325a83710eSEric Fiselier
337fc6a556SMarshall Clow #include "test_macros.h"
347fc6a556SMarshall Clow
3506e2b737SArthur O'Dwyer TEST_CONSTEXPR_CXX20
test()3606e2b737SArthur O'Dwyer bool test()
375a83710eSEric Fiselier {
385a83710eSEric Fiselier {
39a0d87857SStephan T. Lavavej typedef std::pair<long, char> T0;
40a0d87857SStephan T. Lavavej typedef std::tuple<long long, short> T1;
41a0d87857SStephan T. Lavavej T0 t0(2, 'a');
425a83710eSEric Fiselier T1 t1;
435a83710eSEric Fiselier t1 = t0;
445a83710eSEric Fiselier assert(std::get<0>(t1) == 2);
455a83710eSEric Fiselier assert(std::get<1>(t1) == short('a'));
465a83710eSEric Fiselier }
4706e2b737SArthur O'Dwyer return true;
4806e2b737SArthur O'Dwyer }
4906e2b737SArthur O'Dwyer
main(int,char **)5006e2b737SArthur O'Dwyer int main(int, char**)
5106e2b737SArthur O'Dwyer {
5206e2b737SArthur O'Dwyer test();
5306e2b737SArthur O'Dwyer #if TEST_STD_VER >= 20
5406e2b737SArthur O'Dwyer static_assert(test());
5506e2b737SArthur O'Dwyer #endif
5606e2b737SArthur O'Dwyer
5782c4701dSzoecarver {
5882c4701dSzoecarver // test that the implicitly generated copy assignment operator
5982c4701dSzoecarver // is properly deleted
6082c4701dSzoecarver using T = std::tuple<int, int>;
6182c4701dSzoecarver using P = std::tuple<std::unique_ptr<int>, std::unique_ptr<int>>;
625f5416e1SLouis Dionne static_assert(!std::is_assignable<T&, const P &>::value, "");
6382c4701dSzoecarver }
64a0839b14SLouis Dionne {
65a0839b14SLouis Dionne typedef std::tuple<NothrowCopyAssignable, long> Tuple;
66a0839b14SLouis Dionne typedef std::pair<NothrowCopyAssignable, int> Pair;
67a0839b14SLouis Dionne static_assert(std::is_nothrow_assignable<Tuple&, Pair const&>::value, "");
68a0839b14SLouis Dionne static_assert(std::is_nothrow_assignable<Tuple&, Pair&>::value, "");
69a0839b14SLouis Dionne static_assert(std::is_nothrow_assignable<Tuple&, Pair const&&>::value, "");
70a0839b14SLouis Dionne }
71a0839b14SLouis Dionne {
72a0839b14SLouis Dionne typedef std::tuple<PotentiallyThrowingCopyAssignable, long> Tuple;
73a0839b14SLouis Dionne typedef std::pair<PotentiallyThrowingCopyAssignable, int> Pair;
74a0839b14SLouis Dionne static_assert(std::is_assignable<Tuple&, Pair const&>::value, "");
75a0839b14SLouis Dionne static_assert(!std::is_nothrow_assignable<Tuple&, Pair const&>::value, "");
76a0839b14SLouis Dionne
77a0839b14SLouis Dionne static_assert(std::is_assignable<Tuple&, Pair&>::value, "");
78a0839b14SLouis Dionne static_assert(!std::is_nothrow_assignable<Tuple&, Pair&>::value, "");
79a0839b14SLouis Dionne
80a0839b14SLouis Dionne static_assert(std::is_assignable<Tuple&, Pair const&&>::value, "");
81a0839b14SLouis Dionne static_assert(!std::is_nothrow_assignable<Tuple&, Pair const&&>::value, "");
82a0839b14SLouis Dionne }
832df59c50SJF Bastien
842df59c50SJF Bastien return 0;
855a83710eSEric Fiselier }
86