GDB (xrefs)
unittests
optional
assignment
5.cc
Go to the documentation of this file.
1
// Copyright (C) 2013-2018 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_5
{
19
20
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
void
test
()
32
{
33
using
O =
gdb::optional<value_type>
;
34
35
// Check std::nullopt_t and 'default' (= {}) assignment
36
37
#ifndef GDB_OPTIONAL
38
{
39
O o;
40
o = std::nullopt;
41
VERIFY
( !o );
42
}
43
#endif
44
45
#ifndef GDB_OPTIONAL
46
{
47
O o {
gdb::in_place
};
48
o = std::nullopt;
49
VERIFY
( !o );
50
}
51
#endif
52
53
#ifndef GDB_OPTIONAL
54
{
55
O o;
56
o = {};
57
VERIFY
( !o );
58
}
59
#endif
60
61
#ifndef GDB_OPTIONAL
62
{
63
O o {
gdb::in_place
};
64
o = {};
65
VERIFY
( !o );
66
}
67
#endif
68
{
69
gdb::optional<std::vector<int>
> ovi{{1, 2, 3}};
70
VERIFY
(ovi->size() == 3);
71
VERIFY
((*ovi)[0] == 1 && (*ovi)[1] == 2 && (*ovi)[2] == 3);
72
ovi = {4, 5, 6, 7};
73
VERIFY
(ovi->size() == 4);
74
VERIFY
((*ovi)[0] == 4 && (*ovi)[1] == 5 &&
75
(*ovi)[2] == 6 && (*ovi)[3] == 7);
76
}
77
VERIFY
(
counter
== 0 );
78
}
79
80
}
// namespace assign_5
assign_5::mixin_counter
Definition:
5.cc:22
gdb::in_place
constexpr gdb::in_place_t in_place
Definition:
gdb_optional.h:33
assign_5::value_type
Definition:
5.cc:29
VERIFY
#define VERIFY
Definition:
optional-selftests.c:31
assign_5::test
void test()
Definition:
5.cc:31
assign_5
Definition:
5.cc:18
assign_5::counter
int counter
Definition:
5.cc:20
assign_5::mixin_counter::mixin_counter
mixin_counter()
Definition:
5.cc:24
gdb::optional
Definition:
gdb_optional.h:51
assign_5::mixin_counter::~mixin_counter
~mixin_counter()
Definition:
5.cc:26
assign_5::mixin_counter::mixin_counter
mixin_counter(mixin_counter const &)
Definition:
5.cc:25
Generated by
1.8.14