libstdc++: Make std::vector<bool>::reference constructor private [PR115098]
[official-gcc.git] / libstdc++-v3 / include / bits / enable_special_members.h
blob73a9b0202ce5b85f71fe7c828f133a25ab6c9993
1 // <bits/enable_special_members.h> -*- C++ -*-
3 // Copyright (C) 2013-2024 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.
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;
47 /**
48 * @brief A mixin helper to conditionally enable or disable the default
49 * constructor.
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&)
57 noexcept = default;
58 constexpr _Enable_default_constructor(_Enable_default_constructor&&)
59 noexcept = default;
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.
66 constexpr explicit
67 _Enable_default_constructor(_Enable_default_constructor_tag) { }
71 /**
72 * @brief A mixin helper to conditionally enable or disable the default
73 * destructor.
74 * @sa _Enable_special_members
76 template<bool _Switch, typename _Tag = void>
77 struct _Enable_destructor { };
79 /**
80 * @brief A mixin helper to conditionally enable or disable the copy/move
81 * special members.
82 * @sa _Enable_special_members
84 template<bool _Copy, bool _CopyAssignment,
85 bool _Move, bool _MoveAssignment,
86 typename _Tag = void>
87 struct _Enable_copy_move { };
89 /**
90 * @brief A mixin helper to conditionally enable or disable the special
91 * members.
93 * The @c _Tag type parameter is to make mixin bases unique and thus avoid
94 * ambiguities.
96 template<bool _Default, bool _Destructor,
97 bool _Copy, bool _CopyAssignment,
98 bool _Move, bool _MoveAssignment,
99 typename _Tag = void>
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,
105 _Tag>
106 { };
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&)
115 noexcept = default;
116 constexpr _Enable_default_constructor(_Enable_default_constructor&&)
117 noexcept = default;
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.
124 constexpr explicit
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;
138 _Enable_copy_move&
139 operator=(_Enable_copy_move const&) noexcept = default;
140 _Enable_copy_move&
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;
150 _Enable_copy_move&
151 operator=(_Enable_copy_move const&) noexcept = delete;
152 _Enable_copy_move&
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;
162 _Enable_copy_move&
163 operator=(_Enable_copy_move const&) noexcept = delete;
164 _Enable_copy_move&
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;
174 _Enable_copy_move&
175 operator=(_Enable_copy_move const&) noexcept = default;
176 _Enable_copy_move&
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;
186 _Enable_copy_move&
187 operator=(_Enable_copy_move const&) noexcept = default;
188 _Enable_copy_move&
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;
198 _Enable_copy_move&
199 operator=(_Enable_copy_move const&) noexcept = delete;
200 _Enable_copy_move&
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;
210 _Enable_copy_move&
211 operator=(_Enable_copy_move const&) noexcept = delete;
212 _Enable_copy_move&
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;
222 _Enable_copy_move&
223 operator=(_Enable_copy_move const&) noexcept = default;
224 _Enable_copy_move&
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;
234 _Enable_copy_move&
235 operator=(_Enable_copy_move const&) noexcept = default;
236 _Enable_copy_move&
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;
246 _Enable_copy_move&
247 operator=(_Enable_copy_move const&) noexcept = delete;
248 _Enable_copy_move&
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;
258 _Enable_copy_move&
259 operator=(_Enable_copy_move const&) noexcept = delete;
260 _Enable_copy_move&
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;
270 _Enable_copy_move&
271 operator=(_Enable_copy_move const&) noexcept = default;
272 _Enable_copy_move&
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;
282 _Enable_copy_move&
283 operator=(_Enable_copy_move const&) noexcept = default;
284 _Enable_copy_move&
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;
294 _Enable_copy_move&
295 operator=(_Enable_copy_move const&) noexcept = delete;
296 _Enable_copy_move&
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;
306 _Enable_copy_move&
307 operator=(_Enable_copy_move const&) noexcept = delete;
308 _Enable_copy_move&
309 operator=(_Enable_copy_move&&) noexcept = delete;
312 /// @endcond
313 _GLIBCXX_END_NAMESPACE_VERSION
314 } // namespace std
316 #endif // _ENABLE_SPECIAL_MEMBERS_H