enable_special_members.h 12 KB

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