enable_special_members.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. // <bits/enable_special_members.h> -*- C++ -*-
  2. // Copyright (C) 2013-2021 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  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. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file bits/enable_special_members.h
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly.
  23. */
  24. #ifndef _ENABLE_SPECIAL_MEMBERS_H
  25. #define _ENABLE_SPECIAL_MEMBERS_H 1
  26. #pragma GCC system_header
  27. #include <bits/c++config.h>
  28. namespace std _GLIBCXX_VISIBILITY(default)
  29. {
  30. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  31. struct _Enable_default_constructor_tag
  32. {
  33. explicit constexpr _Enable_default_constructor_tag() = default;
  34. };
  35. /**
  36. * @brief A mixin helper to conditionally enable or disable the default
  37. * constructor.
  38. * @sa _Enable_special_members
  39. */
  40. template<bool _Switch, typename _Tag = void>
  41. struct _Enable_default_constructor
  42. {
  43. constexpr _Enable_default_constructor() noexcept = default;
  44. constexpr _Enable_default_constructor(_Enable_default_constructor const&)
  45. noexcept = default;
  46. constexpr _Enable_default_constructor(_Enable_default_constructor&&)
  47. noexcept = default;
  48. _Enable_default_constructor&
  49. operator=(_Enable_default_constructor const&) noexcept = default;
  50. _Enable_default_constructor&
  51. operator=(_Enable_default_constructor&&) noexcept = default;
  52. // Can be used in other ctors.
  53. constexpr explicit
  54. _Enable_default_constructor(_Enable_default_constructor_tag) { }
  55. };
  56. /**
  57. * @brief A mixin helper to conditionally enable or disable the default
  58. * destructor.
  59. * @sa _Enable_special_members
  60. */
  61. template<bool _Switch, typename _Tag = void>
  62. struct _Enable_destructor { };
  63. /**
  64. * @brief A mixin helper to conditionally enable or disable the copy/move
  65. * special members.
  66. * @sa _Enable_special_members
  67. */
  68. template<bool _Copy, bool _CopyAssignment,
  69. bool _Move, bool _MoveAssignment,
  70. typename _Tag = void>
  71. struct _Enable_copy_move { };
  72. /**
  73. * @brief A mixin helper to conditionally enable or disable the special
  74. * members.
  75. *
  76. * The @c _Tag type parameter is to make mixin bases unique and thus avoid
  77. * ambiguities.
  78. */
  79. template<bool _Default, bool _Destructor,
  80. bool _Copy, bool _CopyAssignment,
  81. bool _Move, bool _MoveAssignment,
  82. typename _Tag = void>
  83. struct _Enable_special_members
  84. : private _Enable_default_constructor<_Default, _Tag>,
  85. private _Enable_destructor<_Destructor, _Tag>,
  86. private _Enable_copy_move<_Copy, _CopyAssignment,
  87. _Move, _MoveAssignment,
  88. _Tag>
  89. { };
  90. // Boilerplate follows.
  91. template<typename _Tag>
  92. struct _Enable_default_constructor<false, _Tag>
  93. {
  94. constexpr _Enable_default_constructor() noexcept = delete;
  95. constexpr _Enable_default_constructor(_Enable_default_constructor const&)
  96. noexcept = default;
  97. constexpr _Enable_default_constructor(_Enable_default_constructor&&)
  98. noexcept = default;
  99. _Enable_default_constructor&
  100. operator=(_Enable_default_constructor const&) noexcept = default;
  101. _Enable_default_constructor&
  102. operator=(_Enable_default_constructor&&) noexcept = default;
  103. // Can be used in other ctors.
  104. constexpr explicit
  105. _Enable_default_constructor(_Enable_default_constructor_tag) { }
  106. };
  107. template<typename _Tag>
  108. struct _Enable_destructor<false, _Tag>
  109. { ~_Enable_destructor() noexcept = delete; };
  110. template<typename _Tag>
  111. struct _Enable_copy_move<false, true, true, true, _Tag>
  112. {
  113. constexpr _Enable_copy_move() noexcept = default;
  114. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
  115. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
  116. _Enable_copy_move&
  117. operator=(_Enable_copy_move const&) noexcept = default;
  118. _Enable_copy_move&
  119. operator=(_Enable_copy_move&&) noexcept = default;
  120. };
  121. template<typename _Tag>
  122. struct _Enable_copy_move<true, false, true, true, _Tag>
  123. {
  124. constexpr _Enable_copy_move() noexcept = default;
  125. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
  126. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
  127. _Enable_copy_move&
  128. operator=(_Enable_copy_move const&) noexcept = delete;
  129. _Enable_copy_move&
  130. operator=(_Enable_copy_move&&) noexcept = default;
  131. };
  132. template<typename _Tag>
  133. struct _Enable_copy_move<false, false, true, true, _Tag>
  134. {
  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 = delete;
  140. _Enable_copy_move&
  141. operator=(_Enable_copy_move&&) noexcept = default;
  142. };
  143. template<typename _Tag>
  144. struct _Enable_copy_move<true, true, false, true, _Tag>
  145. {
  146. constexpr _Enable_copy_move() noexcept = default;
  147. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
  148. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
  149. _Enable_copy_move&
  150. operator=(_Enable_copy_move const&) noexcept = default;
  151. _Enable_copy_move&
  152. operator=(_Enable_copy_move&&) noexcept = default;
  153. };
  154. template<typename _Tag>
  155. struct _Enable_copy_move<false, true, false, true, _Tag>
  156. {
  157. constexpr _Enable_copy_move() noexcept = default;
  158. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
  159. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
  160. _Enable_copy_move&
  161. operator=(_Enable_copy_move const&) noexcept = default;
  162. _Enable_copy_move&
  163. operator=(_Enable_copy_move&&) noexcept = default;
  164. };
  165. template<typename _Tag>
  166. struct _Enable_copy_move<true, false, false, true, _Tag>
  167. {
  168. constexpr _Enable_copy_move() noexcept = default;
  169. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
  170. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
  171. _Enable_copy_move&
  172. operator=(_Enable_copy_move const&) noexcept = delete;
  173. _Enable_copy_move&
  174. operator=(_Enable_copy_move&&) noexcept = default;
  175. };
  176. template<typename _Tag>
  177. struct _Enable_copy_move<false, false, 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 = delete;
  184. _Enable_copy_move&
  185. operator=(_Enable_copy_move&&) noexcept = default;
  186. };
  187. template<typename _Tag>
  188. struct _Enable_copy_move<true, true, true, false, _Tag>
  189. {
  190. constexpr _Enable_copy_move() noexcept = default;
  191. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
  192. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
  193. _Enable_copy_move&
  194. operator=(_Enable_copy_move const&) noexcept = default;
  195. _Enable_copy_move&
  196. operator=(_Enable_copy_move&&) noexcept = delete;
  197. };
  198. template<typename _Tag>
  199. struct _Enable_copy_move<false, true, true, false, _Tag>
  200. {
  201. constexpr _Enable_copy_move() noexcept = default;
  202. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
  203. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
  204. _Enable_copy_move&
  205. operator=(_Enable_copy_move const&) noexcept = default;
  206. _Enable_copy_move&
  207. operator=(_Enable_copy_move&&) noexcept = delete;
  208. };
  209. template<typename _Tag>
  210. struct _Enable_copy_move<true, false, true, false, _Tag>
  211. {
  212. constexpr _Enable_copy_move() noexcept = default;
  213. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
  214. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
  215. _Enable_copy_move&
  216. operator=(_Enable_copy_move const&) noexcept = delete;
  217. _Enable_copy_move&
  218. operator=(_Enable_copy_move&&) noexcept = delete;
  219. };
  220. template<typename _Tag>
  221. struct _Enable_copy_move<false, false, true, false, _Tag>
  222. {
  223. constexpr _Enable_copy_move() noexcept = default;
  224. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
  225. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default;
  226. _Enable_copy_move&
  227. operator=(_Enable_copy_move const&) noexcept = delete;
  228. _Enable_copy_move&
  229. operator=(_Enable_copy_move&&) noexcept = delete;
  230. };
  231. template<typename _Tag>
  232. struct _Enable_copy_move<true, true, false, false, _Tag>
  233. {
  234. constexpr _Enable_copy_move() noexcept = default;
  235. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
  236. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
  237. _Enable_copy_move&
  238. operator=(_Enable_copy_move const&) noexcept = default;
  239. _Enable_copy_move&
  240. operator=(_Enable_copy_move&&) noexcept = delete;
  241. };
  242. template<typename _Tag>
  243. struct _Enable_copy_move<false, true, false, false, _Tag>
  244. {
  245. constexpr _Enable_copy_move() noexcept = default;
  246. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
  247. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
  248. _Enable_copy_move&
  249. operator=(_Enable_copy_move const&) noexcept = default;
  250. _Enable_copy_move&
  251. operator=(_Enable_copy_move&&) noexcept = delete;
  252. };
  253. template<typename _Tag>
  254. struct _Enable_copy_move<true, false, false, false, _Tag>
  255. {
  256. constexpr _Enable_copy_move() noexcept = default;
  257. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default;
  258. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
  259. _Enable_copy_move&
  260. operator=(_Enable_copy_move const&) noexcept = delete;
  261. _Enable_copy_move&
  262. operator=(_Enable_copy_move&&) noexcept = delete;
  263. };
  264. template<typename _Tag>
  265. struct _Enable_copy_move<false, false, false, false, _Tag>
  266. {
  267. constexpr _Enable_copy_move() noexcept = default;
  268. constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete;
  269. constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete;
  270. _Enable_copy_move&
  271. operator=(_Enable_copy_move const&) noexcept = delete;
  272. _Enable_copy_move&
  273. operator=(_Enable_copy_move&&) noexcept = delete;
  274. };
  275. _GLIBCXX_END_NAMESPACE_VERSION
  276. } // namespace std
  277. #endif // _ENABLE_SPECIAL_MEMBERS_H