1 // <bits/enable_special_members.h> -*- C++ -*-
3 // Copyright (C) 2013-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file bits/enable_special_members.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly.
30 #ifndef _ENABLE_SPECIAL_MEMBERS_H
31 #define _ENABLE_SPECIAL_MEMBERS_H 1
33 #pragma GCC system_header
35 #include <bits/c++config.h>
37 namespace std
_GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 /// @cond undocumented
42 struct _Enable_default_constructor_tag
44 explicit constexpr _Enable_default_constructor_tag() = default;
48 * @brief A mixin helper to conditionally enable or disable the default
50 * @sa _Enable_special_members
52 template<bool _Switch
, typename _Tag
= void>
53 struct _Enable_default_constructor
55 constexpr _Enable_default_constructor() noexcept
= default;
56 constexpr _Enable_default_constructor(_Enable_default_constructor
const&)
58 constexpr _Enable_default_constructor(_Enable_default_constructor
&&)
60 _Enable_default_constructor
&
61 operator=(_Enable_default_constructor
const&) noexcept
= default;
62 _Enable_default_constructor
&
63 operator=(_Enable_default_constructor
&&) noexcept
= default;
65 // Can be used in other ctors.
67 _Enable_default_constructor(_Enable_default_constructor_tag
) { }
72 * @brief A mixin helper to conditionally enable or disable the default
74 * @sa _Enable_special_members
76 template<bool _Switch
, typename _Tag
= void>
77 struct _Enable_destructor
{ };
80 * @brief A mixin helper to conditionally enable or disable the copy/move
82 * @sa _Enable_special_members
84 template<bool _Copy
, bool _CopyAssignment
,
85 bool _Move
, bool _MoveAssignment
,
87 struct _Enable_copy_move
{ };
90 * @brief A mixin helper to conditionally enable or disable the special
93 * The @c _Tag type parameter is to make mixin bases unique and thus avoid
96 template<bool _Default
, bool _Destructor
,
97 bool _Copy
, bool _CopyAssignment
,
98 bool _Move
, bool _MoveAssignment
,
100 struct _Enable_special_members
101 : private _Enable_default_constructor
<_Default
, _Tag
>,
102 private _Enable_destructor
<_Destructor
, _Tag
>,
103 private _Enable_copy_move
<_Copy
, _CopyAssignment
,
104 _Move
, _MoveAssignment
,
108 // Boilerplate follows.
110 template<typename _Tag
>
111 struct _Enable_default_constructor
<false, _Tag
>
113 constexpr _Enable_default_constructor() noexcept
= delete;
114 constexpr _Enable_default_constructor(_Enable_default_constructor
const&)
116 constexpr _Enable_default_constructor(_Enable_default_constructor
&&)
118 _Enable_default_constructor
&
119 operator=(_Enable_default_constructor
const&) noexcept
= default;
120 _Enable_default_constructor
&
121 operator=(_Enable_default_constructor
&&) noexcept
= default;
123 // Can be used in other ctors.
125 _Enable_default_constructor(_Enable_default_constructor_tag
) { }
128 template<typename _Tag
>
129 struct _Enable_destructor
<false, _Tag
>
130 { ~_Enable_destructor() noexcept
= delete; };
132 template<typename _Tag
>
133 struct _Enable_copy_move
<false, true, true, true, _Tag
>
135 constexpr _Enable_copy_move() noexcept
= default;
136 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
137 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= default;
139 operator=(_Enable_copy_move
const&) noexcept
= default;
141 operator=(_Enable_copy_move
&&) noexcept
= default;
144 template<typename _Tag
>
145 struct _Enable_copy_move
<true, false, true, true, _Tag
>
147 constexpr _Enable_copy_move() noexcept
= default;
148 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= default;
149 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= default;
151 operator=(_Enable_copy_move
const&) noexcept
= delete;
153 operator=(_Enable_copy_move
&&) noexcept
= default;
156 template<typename _Tag
>
157 struct _Enable_copy_move
<false, false, true, true, _Tag
>
159 constexpr _Enable_copy_move() noexcept
= default;
160 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
161 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= default;
163 operator=(_Enable_copy_move
const&) noexcept
= delete;
165 operator=(_Enable_copy_move
&&) noexcept
= default;
168 template<typename _Tag
>
169 struct _Enable_copy_move
<true, true, false, true, _Tag
>
171 constexpr _Enable_copy_move() noexcept
= default;
172 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= default;
173 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
175 operator=(_Enable_copy_move
const&) noexcept
= default;
177 operator=(_Enable_copy_move
&&) noexcept
= default;
180 template<typename _Tag
>
181 struct _Enable_copy_move
<false, true, false, true, _Tag
>
183 constexpr _Enable_copy_move() noexcept
= default;
184 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
185 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
187 operator=(_Enable_copy_move
const&) noexcept
= default;
189 operator=(_Enable_copy_move
&&) noexcept
= default;
192 template<typename _Tag
>
193 struct _Enable_copy_move
<true, false, false, true, _Tag
>
195 constexpr _Enable_copy_move() noexcept
= default;
196 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= default;
197 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
199 operator=(_Enable_copy_move
const&) noexcept
= delete;
201 operator=(_Enable_copy_move
&&) noexcept
= default;
204 template<typename _Tag
>
205 struct _Enable_copy_move
<false, false, false, true, _Tag
>
207 constexpr _Enable_copy_move() noexcept
= default;
208 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
209 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
211 operator=(_Enable_copy_move
const&) noexcept
= delete;
213 operator=(_Enable_copy_move
&&) noexcept
= default;
216 template<typename _Tag
>
217 struct _Enable_copy_move
<true, true, true, false, _Tag
>
219 constexpr _Enable_copy_move() noexcept
= default;
220 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= default;
221 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= default;
223 operator=(_Enable_copy_move
const&) noexcept
= default;
225 operator=(_Enable_copy_move
&&) noexcept
= delete;
228 template<typename _Tag
>
229 struct _Enable_copy_move
<false, true, true, false, _Tag
>
231 constexpr _Enable_copy_move() noexcept
= default;
232 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
233 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= default;
235 operator=(_Enable_copy_move
const&) noexcept
= default;
237 operator=(_Enable_copy_move
&&) noexcept
= delete;
240 template<typename _Tag
>
241 struct _Enable_copy_move
<true, false, true, false, _Tag
>
243 constexpr _Enable_copy_move() noexcept
= default;
244 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= default;
245 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= default;
247 operator=(_Enable_copy_move
const&) noexcept
= delete;
249 operator=(_Enable_copy_move
&&) noexcept
= delete;
252 template<typename _Tag
>
253 struct _Enable_copy_move
<false, false, true, false, _Tag
>
255 constexpr _Enable_copy_move() noexcept
= default;
256 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
257 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= default;
259 operator=(_Enable_copy_move
const&) noexcept
= delete;
261 operator=(_Enable_copy_move
&&) noexcept
= delete;
264 template<typename _Tag
>
265 struct _Enable_copy_move
<true, true, false, false, _Tag
>
267 constexpr _Enable_copy_move() noexcept
= default;
268 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= default;
269 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
271 operator=(_Enable_copy_move
const&) noexcept
= default;
273 operator=(_Enable_copy_move
&&) noexcept
= delete;
276 template<typename _Tag
>
277 struct _Enable_copy_move
<false, true, false, false, _Tag
>
279 constexpr _Enable_copy_move() noexcept
= default;
280 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
281 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
283 operator=(_Enable_copy_move
const&) noexcept
= default;
285 operator=(_Enable_copy_move
&&) noexcept
= delete;
288 template<typename _Tag
>
289 struct _Enable_copy_move
<true, false, false, false, _Tag
>
291 constexpr _Enable_copy_move() noexcept
= default;
292 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= default;
293 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
295 operator=(_Enable_copy_move
const&) noexcept
= delete;
297 operator=(_Enable_copy_move
&&) noexcept
= delete;
300 template<typename _Tag
>
301 struct _Enable_copy_move
<false, false, false, false, _Tag
>
303 constexpr _Enable_copy_move() noexcept
= default;
304 constexpr _Enable_copy_move(_Enable_copy_move
const&) noexcept
= delete;
305 constexpr _Enable_copy_move(_Enable_copy_move
&&) noexcept
= delete;
307 operator=(_Enable_copy_move
const&) noexcept
= delete;
309 operator=(_Enable_copy_move
&&) noexcept
= delete;
313 _GLIBCXX_END_NAMESPACE_VERSION
316 #endif // _ENABLE_SPECIAL_MEMBERS_H