Commit | Line | Data |
---|---|---|
e2882c85 | 1 | // Copyright (C) 2013-2018 Free Software Foundation, Inc. |
d35d1958 PA |
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 |