GDB (xrefs)
6.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_6 {
19 
20 int counter = 0;
21 
23 {
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 void test()
38 {
39  using O = gdb::optional<value_type>;
40 
41  // Check emplace
42 
43  {
44  O o;
45  o.emplace();
46  VERIFY( o && o->state == 0 );
47  }
48  {
49  O o { gdb::in_place, 0 };
50  o.emplace();
51  VERIFY( o && o->state == 0 );
52  }
53 
54  {
55  O o;
56  o.emplace(0);
57  VERIFY( o && o->state == 1 );
58  }
59  {
60  O o { gdb::in_place };
61  o.emplace(0);
62  VERIFY( o && o->state == 1 );
63  }
64 
65 #ifndef GDB_OPTIONAL
66  {
67  O o;
68  o.emplace({ 'a' }, "");
69  VERIFY( o && o->state == 2 );
70  }
71  {
72  O o { gdb::in_place };
73  o.emplace({ 'a' }, "");
74  VERIFY( o && o->state == 2 );
75  }
76 #endif
77  {
78  O o;
79  VERIFY(&o.emplace(0) == &*o);
80 #ifndef GDB_OPTIONAL
81  VERIFY(&o.emplace({ 'a' }, "") == &*o);
82 #endif
83  }
84 
85  static_assert( !std::is_constructible<O, std::initializer_list<int>, int>(), "" );
86 
87  VERIFY( counter == 0 );
88 }
89 
90 } // namespace assign_6
constexpr gdb::in_place_t in_place
Definition: gdb_optional.h:33
int counter
Definition: 6.cc:20
Definition: 6.cc:18
#define VERIFY
value_type(std::initializer_list< char >, const char *)
Definition: 6.cc:33
T & emplace(Args &&... args)
Definition: gdb_optional.h:152
mixin_counter(mixin_counter const &)
Definition: 6.cc:25
value_type(int)
Definition: 6.cc:32
void test()
Definition: 6.cc:37