GDB (xrefs)
Loading...
Searching...
No Matches
gdb
unittests
optional
assignment
6.cc
Go to the documentation of this file.
1
// Copyright (C) 2013-2023 Free Software Foundation, Inc.
2
//
3
// This file is part of the GNU ISO C++ Library. This library is free
4
// software; you can redistribute it and/or modify it under the
5
// terms of the GNU General Public License as published by the
6
// Free Software Foundation; either version 3, or (at your option)
7
// any later version.
8
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
14
// You should have received a copy of the GNU General Public License along
15
// with this library; see the file COPYING3. If not see
16
// <http://www.gnu.org/licenses/>.
17
18
namespace
assign_6
{
19
20
static
int
counter
= 0;
21
22
struct
mixin_counter
23
{
24
mixin_counter
() { ++
counter
; }
25
mixin_counter
(
mixin_counter
const
&) { ++
counter
; }
26
~mixin_counter
() { --
counter
; }
27
};
28
29
struct
value_type
:
private
mixin_counter
30
{
31
value_type
() =
default
;
32
value_type
(
int
) :
state
(1) { }
33
value_type
(std::initializer_list<char>,
const
char
*) :
state
(2) { }
34
int
state
= 0;
35
};
36
37
static
void
38
test
()
39
{
40
using
O = gdb::optional<value_type>;
41
42
// Check emplace
43
44
{
45
O o;
46
o.emplace();
47
VERIFY
( o && o->state == 0 );
48
}
49
{
50
O o { gdb::in_place, 0 };
51
o.emplace();
52
VERIFY
( o && o->state == 0 );
53
}
54
55
{
56
O o;
57
o.emplace(0);
58
VERIFY
( o && o->state == 1 );
59
}
60
{
61
O o { gdb::in_place };
62
o.emplace(0);
63
VERIFY
( o && o->state == 1 );
64
}
65
66
#ifndef GDB_OPTIONAL
67
{
68
O o;
69
o.emplace({
'a'
},
""
);
70
VERIFY
( o && o->state == 2 );
71
}
72
{
73
O o { gdb::in_place };
74
o.emplace({
'a'
},
""
);
75
VERIFY
( o && o->state == 2 );
76
}
77
#endif
78
{
79
O o;
80
VERIFY
(&o.emplace(0) == &*o);
81
#ifndef GDB_OPTIONAL
82
VERIFY
(&o.emplace({
'a'
},
""
) == &*o);
83
#endif
84
}
85
86
static_assert
( !std::is_constructible<O, std::initializer_list<int>,
int
>(),
""
);
87
88
VERIFY
(
counter
== 0 );
89
}
90
91
}
// namespace assign_6
VERIFY
#define VERIFY(x)
assign_6
Definition
6.cc:18
assign_6::test
static void test()
Definition
6.cc:38
assign_6::counter
static int counter
Definition
6.cc:20
assign_6::mixin_counter
Definition
6.cc:23
assign_6::mixin_counter::mixin_counter
mixin_counter()
Definition
6.cc:24
assign_6::mixin_counter::~mixin_counter
~mixin_counter()
Definition
6.cc:26
assign_6::mixin_counter::mixin_counter
mixin_counter(mixin_counter const &)
Definition
6.cc:25
assign_6::value_type
Definition
6.cc:30
assign_6::value_type::value_type
value_type()=default
assign_6::value_type::value_type
value_type(std::initializer_list< char >, const char *)
Definition
6.cc:33
assign_6::value_type::state
int state
Definition
6.cc:34
assign_6::value_type::value_type
value_type(int)
Definition
6.cc:32
Generated by
1.10.0