libstdc++
enable_special_members.h
Go to the documentation of this file.
1 // <bits/enable_special_members.h> -*- C++ -*-
2 
3 // Copyright (C) 2013-2014 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 /**
40  * @brief A mixin helper to conditionally enable or disable the default
41  * constructor.
42  * @sa _Enable_special_members
43  */
44 template<bool _Switch, typename _Tag = void>
46 
47 
48 /**
49  * @brief A mixin helper to conditionally enable or disable the default
50  * destructor.
51  * @sa _Enable_special_members
52  */
53 template<bool _Switch, typename _Tag = void>
54  struct _Enable_destructor { };
55 
56 /**
57  * @brief A mixin helper to conditionally enable or disable the copy/move
58  * special members.
59  * @sa _Enable_special_members
60  */
61 template<bool _Copy, bool _CopyAssignment,
62  bool _Move, bool _MoveAssignment,
63  typename _Tag = void>
64  struct _Enable_copy_move { };
65 
66 /**
67  * @brief A mixin helper to conditionally enable or disable the special
68  * members.
69  *
70  * The @c _Tag type parameter is to make mixin bases unique and thus avoid
71  * ambiguities.
72  */
73 template<bool _Default, bool _Destructor,
74  bool _Copy, bool _CopyAssignment,
75  bool _Move, bool _MoveAssignment,
76  typename _Tag = void>
78  : private _Enable_default_constructor<_Default, _Tag>,
79  private _Enable_destructor<_Destructor, _Tag>,
80  private _Enable_copy_move<_Copy, _CopyAssignment,
81  _Move, _MoveAssignment,
82  _Tag>
83  { };
84 
85 // Boilerplate follows.
86 
87 template<typename _Tag>
88  struct _Enable_default_constructor<false, _Tag>
89  { constexpr _Enable_default_constructor() noexcept = delete; };
90 
91 template<typename _Tag>
92  struct _Enable_destructor<false, _Tag>
93  { ~_Enable_destructor() noexcept = delete; };
94 
95 template<typename _Tag>
96  struct _Enable_copy_move<false, true, true, true, _Tag>
97  {
98  constexpr _Enable_copy_move() noexcept = default;
99  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
100  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
102  operator=(_Enable_copy_move const&) noexcept = default;
104  operator=(_Enable_copy_move&&) noexcept = default;
105  };
106 
107 template<typename _Tag>
108  struct _Enable_copy_move<true, false, true, true, _Tag>
109  {
110  constexpr _Enable_copy_move() noexcept = default;
111  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
112  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
114  operator=(_Enable_copy_move const&) noexcept = delete;
116  operator=(_Enable_copy_move&&) noexcept = default;
117  };
118 
119 template<typename _Tag>
120  struct _Enable_copy_move<false, false, true, true, _Tag>
121  {
122  constexpr _Enable_copy_move() noexcept = default;
123  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
124  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
126  operator=(_Enable_copy_move const&) noexcept = delete;
128  operator=(_Enable_copy_move&&) noexcept = default;
129  };
130 
131 template<typename _Tag>
132  struct _Enable_copy_move<true, true, false, true, _Tag>
133  {
134  constexpr _Enable_copy_move() noexcept = default;
135  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
136  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
138  operator=(_Enable_copy_move const&) noexcept = default;
140  operator=(_Enable_copy_move&&) noexcept = default;
141  };
142 
143 template<typename _Tag>
144  struct _Enable_copy_move<false, true, false, true, _Tag>
145  {
146  constexpr _Enable_copy_move() noexcept = default;
147  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
148  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
150  operator=(_Enable_copy_move const&) noexcept = default;
152  operator=(_Enable_copy_move&&) noexcept = default;
153  };
154 
155 template<typename _Tag>
156  struct _Enable_copy_move<true, false, false, true, _Tag>
157  {
158  constexpr _Enable_copy_move() noexcept = default;
159  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
160  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
162  operator=(_Enable_copy_move const&) noexcept = delete;
164  operator=(_Enable_copy_move&&) noexcept = default;
165  };
166 
167 template<typename _Tag>
168  struct _Enable_copy_move<false, false, false, true, _Tag>
169  {
170  constexpr _Enable_copy_move() noexcept = default;
171  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
172  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
174  operator=(_Enable_copy_move const&) noexcept = delete;
176  operator=(_Enable_copy_move&&) noexcept = default;
177  };
178 
179 template<typename _Tag>
180  struct _Enable_copy_move<true, true, true, false, _Tag>
181  {
182  constexpr _Enable_copy_move() noexcept = default;
183  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
184  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
186  operator=(_Enable_copy_move const&) noexcept = default;
188  operator=(_Enable_copy_move&&) noexcept = delete;
189  };
190 
191 template<typename _Tag>
192  struct _Enable_copy_move<false, true, true, false, _Tag>
193  {
194  constexpr _Enable_copy_move() noexcept = default;
195  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
196  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
198  operator=(_Enable_copy_move const&) noexcept = default;
200  operator=(_Enable_copy_move&&) noexcept = delete;
201  };
202 
203 template<typename _Tag>
204  struct _Enable_copy_move<true, false, true, false, _Tag>
205  {
206  constexpr _Enable_copy_move() noexcept = default;
207  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
208  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
210  operator=(_Enable_copy_move const&) noexcept = delete;
212  operator=(_Enable_copy_move&&) noexcept = delete;
213  };
214 
215 template<typename _Tag>
216  struct _Enable_copy_move<false, false, true, false, _Tag>
217  {
218  constexpr _Enable_copy_move() noexcept = default;
219  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
220  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
222  operator=(_Enable_copy_move const&) noexcept = delete;
224  operator=(_Enable_copy_move&&) noexcept = delete;
225  };
226 
227 template<typename _Tag>
228  struct _Enable_copy_move<true, true, false, false, _Tag>
229  {
230  constexpr _Enable_copy_move() noexcept = default;
231  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
232  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
234  operator=(_Enable_copy_move const&) noexcept = default;
236  operator=(_Enable_copy_move&&) noexcept = delete;
237  };
238 
239 template<typename _Tag>
240  struct _Enable_copy_move<false, true, false, false, _Tag>
241  {
242  constexpr _Enable_copy_move() noexcept = default;
243  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
244  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
246  operator=(_Enable_copy_move const&) noexcept = default;
248  operator=(_Enable_copy_move&&) noexcept = delete;
249  };
250 
251 template<typename _Tag>
252  struct _Enable_copy_move<true, false, false, false, _Tag>
253  {
254  constexpr _Enable_copy_move() noexcept = default;
255  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
256  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
258  operator=(_Enable_copy_move const&) noexcept = delete;
260  operator=(_Enable_copy_move&&) noexcept = delete;
261  };
262 
263 template<typename _Tag>
264  struct _Enable_copy_move<false, false, false, false, _Tag>
265  {
266  constexpr _Enable_copy_move() noexcept = default;
267  constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
268  constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
270  operator=(_Enable_copy_move const&) noexcept = delete;
272  operator=(_Enable_copy_move&&) noexcept = delete;
273  };
274 
275 _GLIBCXX_END_NAMESPACE_VERSION
276 } // namespace std
277 
278 #endif // _ENABLE_SPECIAL_MEMBERS_H
A mixin helper to conditionally enable or disable the default constructor.
A mixin helper to conditionally enable or disable the default destructor.
A mixin helper to conditionally enable or disable the special members.
A mixin helper to conditionally enable or disable the copy/move special members.