]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/enable_special_members.h
Implement <variant>
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / enable_special_members.h
1 // <bits/enable_special_members.h> -*- C++ -*-
2
3 // Copyright (C) 2013-2016 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
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.
15
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.
19
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/>.
24
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.
28 */
29
30 #ifndef _ENABLE_SPECIAL_MEMBERS_H
31 #define _ENABLE_SPECIAL_MEMBERS_H 1
32
33 #pragma GCC system_header
34
35 namespace std _GLIBCXX_VISIBILITY(default)
36 {
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
38
39 struct _Enable_default_constructor_tag
40 {
41 explicit _Enable_default_constructor_tag() = default;
42 };
43
44 /**
45 * @brief A mixin helper to conditionally enable or disable the default
46 * constructor.
47 * @sa _Enable_special_members
48 */
49 template<bool _Switch, typename _Tag = void>
50 struct _Enable_default_constructor
51 {
52 constexpr _Enable_default_constructor() noexcept = default;
53 constexpr _Enable_default_constructor(_Enable_default_constructor const&)
54 noexcept = default;
55 constexpr _Enable_default_constructor(_Enable_default_constructor&&)
56 noexcept = default;
57 _Enable_default_constructor&
58 operator=(_Enable_default_constructor const&) noexcept = default;
59 _Enable_default_constructor&
60 operator=(_Enable_default_constructor&&) noexcept = default;
61
62 // Can be used in other ctors.
63 constexpr explicit
64 _Enable_default_constructor(_Enable_default_constructor_tag) { }
65 };
66
67
68 /**
69 * @brief A mixin helper to conditionally enable or disable the default
70 * destructor.
71 * @sa _Enable_special_members
72 */
73 template<bool _Switch, typename _Tag = void>
74 struct _Enable_destructor { };
75
76 /**
77 * @brief A mixin helper to conditionally enable or disable the copy/move
78 * special members.
79 * @sa _Enable_special_members
80 */
81 template<bool _Copy, bool _CopyAssignment,
82 bool _Move, bool _MoveAssignment,
83 typename _Tag = void>
84 struct _Enable_copy_move { };
85
86 /**
87 * @brief A mixin helper to conditionally enable or disable the special
88 * members.
89 *
90 * The @c _Tag type parameter is to make mixin bases unique and thus avoid
91 * ambiguities.
92 */
93 template<bool _Default, bool _Destructor,
94 bool _Copy, bool _CopyAssignment,
95 bool _Move, bool _MoveAssignment,
96 typename _Tag = void>
97 struct _Enable_special_members
98 : private _Enable_default_constructor<_Default, _Tag>,
99 private _Enable_destructor<_Destructor, _Tag>,
100 private _Enable_copy_move<_Copy, _CopyAssignment,
101 _Move, _MoveAssignment,
102 _Tag>
103 { };
104
105 // Boilerplate follows.
106
107 template<typename _Tag>
108 struct _Enable_default_constructor<false, _Tag>
109 {
110 constexpr _Enable_default_constructor() noexcept = delete;
111 constexpr _Enable_default_constructor(_Enable_default_constructor const&)
112 noexcept = default;
113 constexpr _Enable_default_constructor(_Enable_default_constructor&&)
114 noexcept = default;
115 _Enable_default_constructor&
116 operator=(_Enable_default_constructor const&) noexcept = default;
117 _Enable_default_constructor&
118 operator=(_Enable_default_constructor&&) noexcept = default;
119
120 // Can be used in other ctors.
121 explicit _Enable_default_constructor(_Enable_default_constructor_tag) { }
122 };
123
124 template<typename _Tag>
125 struct _Enable_destructor<false, _Tag>
126 { ~_Enable_destructor() noexcept = delete; };
127
128 template<typename _Tag>
129 struct _Enable_copy_move<false, true, true, true, _Tag>
130 {
131 constexpr _Enable_copy_move() noexcept = default;
132 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
133 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
134 _Enable_copy_move&
135 operator=(_Enable_copy_move const&) noexcept = default;
136 _Enable_copy_move&
137 operator=(_Enable_copy_move&&) noexcept = default;
138 };
139
140 template<typename _Tag>
141 struct _Enable_copy_move<true, false, true, true, _Tag>
142 {
143 constexpr _Enable_copy_move() noexcept = default;
144 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
145 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
146 _Enable_copy_move&
147 operator=(_Enable_copy_move const&) noexcept = delete;
148 _Enable_copy_move&
149 operator=(_Enable_copy_move&&) noexcept = default;
150 };
151
152 template<typename _Tag>
153 struct _Enable_copy_move<false, false, true, true, _Tag>
154 {
155 constexpr _Enable_copy_move() noexcept = default;
156 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
157 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
158 _Enable_copy_move&
159 operator=(_Enable_copy_move const&) noexcept = delete;
160 _Enable_copy_move&
161 operator=(_Enable_copy_move&&) noexcept = default;
162 };
163
164 template<typename _Tag>
165 struct _Enable_copy_move<true, true, false, true, _Tag>
166 {
167 constexpr _Enable_copy_move() noexcept = default;
168 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
169 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
170 _Enable_copy_move&
171 operator=(_Enable_copy_move const&) noexcept = default;
172 _Enable_copy_move&
173 operator=(_Enable_copy_move&&) noexcept = default;
174 };
175
176 template<typename _Tag>
177 struct _Enable_copy_move<false, true, false, true, _Tag>
178 {
179 constexpr _Enable_copy_move() noexcept = default;
180 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
181 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
182 _Enable_copy_move&
183 operator=(_Enable_copy_move const&) noexcept = default;
184 _Enable_copy_move&
185 operator=(_Enable_copy_move&&) noexcept = default;
186 };
187
188 template<typename _Tag>
189 struct _Enable_copy_move<true, false, false, true, _Tag>
190 {
191 constexpr _Enable_copy_move() noexcept = default;
192 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
193 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
194 _Enable_copy_move&
195 operator=(_Enable_copy_move const&) noexcept = delete;
196 _Enable_copy_move&
197 operator=(_Enable_copy_move&&) noexcept = default;
198 };
199
200 template<typename _Tag>
201 struct _Enable_copy_move<false, false, false, true, _Tag>
202 {
203 constexpr _Enable_copy_move() noexcept = default;
204 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
205 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
206 _Enable_copy_move&
207 operator=(_Enable_copy_move const&) noexcept = delete;
208 _Enable_copy_move&
209 operator=(_Enable_copy_move&&) noexcept = default;
210 };
211
212 template<typename _Tag>
213 struct _Enable_copy_move<true, true, true, false, _Tag>
214 {
215 constexpr _Enable_copy_move() noexcept = default;
216 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
217 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
218 _Enable_copy_move&
219 operator=(_Enable_copy_move const&) noexcept = default;
220 _Enable_copy_move&
221 operator=(_Enable_copy_move&&) noexcept = delete;
222 };
223
224 template<typename _Tag>
225 struct _Enable_copy_move<false, true, true, false, _Tag>
226 {
227 constexpr _Enable_copy_move() noexcept = default;
228 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
229 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
230 _Enable_copy_move&
231 operator=(_Enable_copy_move const&) noexcept = default;
232 _Enable_copy_move&
233 operator=(_Enable_copy_move&&) noexcept = delete;
234 };
235
236 template<typename _Tag>
237 struct _Enable_copy_move<true, false, true, false, _Tag>
238 {
239 constexpr _Enable_copy_move() noexcept = default;
240 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
241 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
242 _Enable_copy_move&
243 operator=(_Enable_copy_move const&) noexcept = delete;
244 _Enable_copy_move&
245 operator=(_Enable_copy_move&&) noexcept = delete;
246 };
247
248 template<typename _Tag>
249 struct _Enable_copy_move<false, false, true, false, _Tag>
250 {
251 constexpr _Enable_copy_move() noexcept = default;
252 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
253 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
254 _Enable_copy_move&
255 operator=(_Enable_copy_move const&) noexcept = delete;
256 _Enable_copy_move&
257 operator=(_Enable_copy_move&&) noexcept = delete;
258 };
259
260 template<typename _Tag>
261 struct _Enable_copy_move<true, true, false, false, _Tag>
262 {
263 constexpr _Enable_copy_move() noexcept = default;
264 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
265 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
266 _Enable_copy_move&
267 operator=(_Enable_copy_move const&) noexcept = default;
268 _Enable_copy_move&
269 operator=(_Enable_copy_move&&) noexcept = delete;
270 };
271
272 template<typename _Tag>
273 struct _Enable_copy_move<false, true, false, false, _Tag>
274 {
275 constexpr _Enable_copy_move() noexcept = default;
276 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
277 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
278 _Enable_copy_move&
279 operator=(_Enable_copy_move const&) noexcept = default;
280 _Enable_copy_move&
281 operator=(_Enable_copy_move&&) noexcept = delete;
282 };
283
284 template<typename _Tag>
285 struct _Enable_copy_move<true, false, false, false, _Tag>
286 {
287 constexpr _Enable_copy_move() noexcept = default;
288 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
289 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
290 _Enable_copy_move&
291 operator=(_Enable_copy_move const&) noexcept = delete;
292 _Enable_copy_move&
293 operator=(_Enable_copy_move&&) noexcept = delete;
294 };
295
296 template<typename _Tag>
297 struct _Enable_copy_move<false, false, false, false, _Tag>
298 {
299 constexpr _Enable_copy_move() noexcept = default;
300 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
301 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
302 _Enable_copy_move&
303 operator=(_Enable_copy_move const&) noexcept = delete;
304 _Enable_copy_move&
305 operator=(_Enable_copy_move&&) noexcept = delete;
306 };
307
308 _GLIBCXX_END_NAMESPACE_VERSION
309 } // namespace std
310
311 #endif // _ENABLE_SPECIAL_MEMBERS_H