xref: /llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/cnstr_with_any.compile.pass.cpp (revision 17f2d1cb9b93d336d4187cd14307bef1ab535808)
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 // UNSUPPORTED: c++03
10 
11 // This test makes sure that we can copy/move a std::tuple containing a type
12 // that checks for copy constructibility itself, like std::any.
13 //
14 // Problem showcased in https://reviews.llvm.org/D96523#2730953.
15 
16 #include <any>
17 #include <tuple>
18 #include <type_traits>
19 #include <utility>
20 
21 #include "test_macros.h"
22 
23 template <class ...Pred>
24 struct And : std::true_type { };
25 
26 template <class P1, class ...Pn>
27 struct And<P1, Pn...>
28   : std::conditional<P1::value, And<Pn...>, std::false_type>::type
29 { };
30 
31 struct any {
32   any();
33   any(any const&) = default;
34 
35   template <class ValueType,
36             class Decayed = typename std::decay<ValueType>::type,
37             class = typename std::enable_if<
38               !std::is_same<Decayed, any>::value &&
39               std::is_copy_constructible<Decayed>::value
40             >::type>
41   any(ValueType&&);
42 };
43 
44 struct A {
45   A();
46   A(any);
47 };
48 
49 #if TEST_STD_VER > 14
50 struct B {
51   B();
52   B(std::any);
53 };
54 #endif
55 
f()56 void f() {
57   {
58     std::tuple<A, int> x;
59     std::tuple<A, int> y = x; (void)y;
60   }
61   {
62     std::tuple<A, int> x;
63     std::tuple<A, int> y = std::move(x); (void)y;
64   }
65 
66 #if TEST_STD_VER > 14
67   {
68     std::tuple<B, int> x;
69     std::tuple<B, int> y = x; (void)y;
70   }
71   {
72     std::tuple<B, int> x;
73     std::tuple<B, int> y = std::move(x); (void)y;
74   }
75 #endif
76 }
77