xref: /llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/const_pair.pass.cpp (revision 5f5416e1c4b418d59f7f944060c8a39ced2189a0)
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& operator=(NothrowCopyAssignable const&) noexcept { return *this; }
26 };
27 struct PotentiallyThrowingCopyAssignable {
28     PotentiallyThrowingCopyAssignable& operator=(PotentiallyThrowingCopyAssignable const&) { return *this; }
29 };
30 
31 #include "test_macros.h"
32 
33 int main(int, char**)
34 {
35     {
36         typedef std::pair<long, char> T0;
37         typedef std::tuple<long long, short> T1;
38         T0 t0(2, 'a');
39         T1 t1;
40         t1 = t0;
41         assert(std::get<0>(t1) == 2);
42         assert(std::get<1>(t1) == short('a'));
43     }
44     {
45         // test that the implicitly generated copy assignment operator
46         // is properly deleted
47         using T = std::tuple<int, int>;
48         using P = std::tuple<std::unique_ptr<int>, std::unique_ptr<int>>;
49         static_assert(!std::is_assignable<T&, const P &>::value, "");
50     }
51     {
52         typedef std::tuple<NothrowCopyAssignable, long> Tuple;
53         typedef std::pair<NothrowCopyAssignable, int> Pair;
54         static_assert(std::is_nothrow_assignable<Tuple&, Pair const&>::value, "");
55         static_assert(std::is_nothrow_assignable<Tuple&, Pair&>::value, "");
56         static_assert(std::is_nothrow_assignable<Tuple&, Pair const&&>::value, "");
57     }
58     {
59         typedef std::tuple<PotentiallyThrowingCopyAssignable, long> Tuple;
60         typedef std::pair<PotentiallyThrowingCopyAssignable, int> Pair;
61         static_assert(std::is_assignable<Tuple&, Pair const&>::value, "");
62         static_assert(!std::is_nothrow_assignable<Tuple&, Pair const&>::value, "");
63 
64         static_assert(std::is_assignable<Tuple&, Pair&>::value, "");
65         static_assert(!std::is_nothrow_assignable<Tuple&, Pair&>::value, "");
66 
67         static_assert(std::is_assignable<Tuple&, Pair const&&>::value, "");
68         static_assert(!std::is_nothrow_assignable<Tuple&, Pair const&&>::value, "");
69     }
70 
71     return 0;
72 }
73