| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
template<class T> |
| 4 |
struct X |
| 5 |
{ |
| 6 |
T first{}; |
| 7 |
|
| 8 |
X& operator=(const X&) = delete; |
| 9 |
X& operator=(const X&) requires requires (T& t) { t = t; } { return *this; } |
| 10 |
}; |
| 11 |
|
| 12 |
// C++20 std::pair<const int, int>: |
| 13 |
using cxx20_pair = X<const int>; |
| 14 |
static_assert( __is_trivially_constructible(cxx20_pair, const cxx20_pair&), "" ); |
| 15 |
static_assert( !__is_assignable(cxx20_pair&, const cxx20_pair&), "" ); |
| 16 |
static_assert( __is_trivially_copyable(cxx20_pair), "" ); |
| 17 |
|
| 18 |
template<bool, typename, typename F> struct conditional { using type = F; }; |
| 19 |
template<typename T, typename F> struct conditional<true, T, F> { using type = T; }; |
| 20 |
|
| 21 |
struct base |
| 22 |
{ |
| 23 |
base() = default; |
| 24 |
~base() = default; |
| 25 |
base(const base&) = default; |
| 26 |
base& operator=(const base&) = delete; |
| 27 |
}; |
| 28 |
|
| 29 |
struct nope; |
| 30 |
|
| 31 |
template<class T> |
| 32 |
struct Y : base |
| 33 |
{ |
| 34 |
T first{}; |
| 35 |
|
| 36 |
Y& operator=(typename conditional<__is_assignable(T&, const T&), const Y&, const nope&>::type) |
| 37 |
{ return *this; } |
| 38 |
}; |
| 39 |
|
| 40 |
// C++17 std::pair<const int, int>: |
| 41 |
using cxx17_pair = Y<const int>; |
| 42 |
static_assert( __is_trivially_constructible(cxx17_pair, const cxx17_pair&), "" ); |
| 43 |
static_assert( ! __is_assignable(cxx17_pair&, const cxx17_pair&), "" ); |
| 44 |
static_assert( __is_trivially_copyable(cxx17_pair), "???" ); |