blob: febd109abd7490830d4226afe0727b3d1c4de99b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// Like cond-triv1.C, but with the declaration order swapped.
// { dg-do compile { target concepts } }
#include <type_traits>
template <typename T>
class optional
{
struct empty {};
union {
empty _ = { };
T value;
};
bool engaged = false;
public:
constexpr optional() = default;
constexpr optional(optional const& o)
: engaged (o.engaged)
{
if (engaged)
new (&value) T (o.value);
}
constexpr optional(optional const&)
requires std::is_trivially_copy_constructible_v<T>
= default;
~optional()
{
if (engaged)
value.~T();
}
~optional()
requires std::is_trivially_destructible_v<T>
= default;
// ...
};
struct A { A(); A(const A&); ~A(); };
static_assert(std::is_trivially_copy_constructible_v<optional<int>>);
static_assert(!std::is_trivially_copy_constructible_v<optional<A>>);
static_assert(std::is_trivially_destructible_v<optional<int>>);
static_assert(!std::is_trivially_destructible_v<optional<A>>);
|