libstdc++
|
00001 // <bits/enable_special_members.h> -*- C++ -*- 00002 00003 // Copyright (C) 2013-2018 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file bits/enable_special_members.h 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. 00028 */ 00029 00030 #ifndef _ENABLE_SPECIAL_MEMBERS_H 00031 #define _ENABLE_SPECIAL_MEMBERS_H 1 00032 00033 #pragma GCC system_header 00034 00035 namespace std _GLIBCXX_VISIBILITY(default) 00036 { 00037 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00038 00039 struct _Enable_default_constructor_tag 00040 { 00041 explicit constexpr _Enable_default_constructor_tag() = default; 00042 }; 00043 00044 /** 00045 * @brief A mixin helper to conditionally enable or disable the default 00046 * constructor. 00047 * @sa _Enable_special_members 00048 */ 00049 template<bool _Switch, typename _Tag = void> 00050 struct _Enable_default_constructor 00051 { 00052 constexpr _Enable_default_constructor() noexcept = default; 00053 constexpr _Enable_default_constructor(_Enable_default_constructor const&) 00054 noexcept = default; 00055 constexpr _Enable_default_constructor(_Enable_default_constructor&&) 00056 noexcept = default; 00057 _Enable_default_constructor& 00058 operator=(_Enable_default_constructor const&) noexcept = default; 00059 _Enable_default_constructor& 00060 operator=(_Enable_default_constructor&&) noexcept = default; 00061 00062 // Can be used in other ctors. 00063 constexpr explicit 00064 _Enable_default_constructor(_Enable_default_constructor_tag) { } 00065 }; 00066 00067 00068 /** 00069 * @brief A mixin helper to conditionally enable or disable the default 00070 * destructor. 00071 * @sa _Enable_special_members 00072 */ 00073 template<bool _Switch, typename _Tag = void> 00074 struct _Enable_destructor { }; 00075 00076 /** 00077 * @brief A mixin helper to conditionally enable or disable the copy/move 00078 * special members. 00079 * @sa _Enable_special_members 00080 */ 00081 template<bool _Copy, bool _CopyAssignment, 00082 bool _Move, bool _MoveAssignment, 00083 typename _Tag = void> 00084 struct _Enable_copy_move { }; 00085 00086 /** 00087 * @brief A mixin helper to conditionally enable or disable the special 00088 * members. 00089 * 00090 * The @c _Tag type parameter is to make mixin bases unique and thus avoid 00091 * ambiguities. 00092 */ 00093 template<bool _Default, bool _Destructor, 00094 bool _Copy, bool _CopyAssignment, 00095 bool _Move, bool _MoveAssignment, 00096 typename _Tag = void> 00097 struct _Enable_special_members 00098 : private _Enable_default_constructor<_Default, _Tag>, 00099 private _Enable_destructor<_Destructor, _Tag>, 00100 private _Enable_copy_move<_Copy, _CopyAssignment, 00101 _Move, _MoveAssignment, 00102 _Tag> 00103 { }; 00104 00105 // Boilerplate follows. 00106 00107 template<typename _Tag> 00108 struct _Enable_default_constructor<false, _Tag> 00109 { 00110 constexpr _Enable_default_constructor() noexcept = delete; 00111 constexpr _Enable_default_constructor(_Enable_default_constructor const&) 00112 noexcept = default; 00113 constexpr _Enable_default_constructor(_Enable_default_constructor&&) 00114 noexcept = default; 00115 _Enable_default_constructor& 00116 operator=(_Enable_default_constructor const&) noexcept = default; 00117 _Enable_default_constructor& 00118 operator=(_Enable_default_constructor&&) noexcept = default; 00119 00120 // Can be used in other ctors. 00121 constexpr explicit 00122 _Enable_default_constructor(_Enable_default_constructor_tag) { } 00123 }; 00124 00125 template<typename _Tag> 00126 struct _Enable_destructor<false, _Tag> 00127 { ~_Enable_destructor() noexcept = delete; }; 00128 00129 template<typename _Tag> 00130 struct _Enable_copy_move<false, true, true, true, _Tag> 00131 { 00132 constexpr _Enable_copy_move() noexcept = default; 00133 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00134 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default; 00135 _Enable_copy_move& 00136 operator=(_Enable_copy_move const&) noexcept = default; 00137 _Enable_copy_move& 00138 operator=(_Enable_copy_move&&) noexcept = default; 00139 }; 00140 00141 template<typename _Tag> 00142 struct _Enable_copy_move<true, false, true, true, _Tag> 00143 { 00144 constexpr _Enable_copy_move() noexcept = default; 00145 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default; 00146 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default; 00147 _Enable_copy_move& 00148 operator=(_Enable_copy_move const&) noexcept = delete; 00149 _Enable_copy_move& 00150 operator=(_Enable_copy_move&&) noexcept = default; 00151 }; 00152 00153 template<typename _Tag> 00154 struct _Enable_copy_move<false, false, true, true, _Tag> 00155 { 00156 constexpr _Enable_copy_move() noexcept = default; 00157 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00158 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default; 00159 _Enable_copy_move& 00160 operator=(_Enable_copy_move const&) noexcept = delete; 00161 _Enable_copy_move& 00162 operator=(_Enable_copy_move&&) noexcept = default; 00163 }; 00164 00165 template<typename _Tag> 00166 struct _Enable_copy_move<true, true, false, true, _Tag> 00167 { 00168 constexpr _Enable_copy_move() noexcept = default; 00169 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default; 00170 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00171 _Enable_copy_move& 00172 operator=(_Enable_copy_move const&) noexcept = default; 00173 _Enable_copy_move& 00174 operator=(_Enable_copy_move&&) noexcept = default; 00175 }; 00176 00177 template<typename _Tag> 00178 struct _Enable_copy_move<false, true, false, true, _Tag> 00179 { 00180 constexpr _Enable_copy_move() noexcept = default; 00181 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00182 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00183 _Enable_copy_move& 00184 operator=(_Enable_copy_move const&) noexcept = default; 00185 _Enable_copy_move& 00186 operator=(_Enable_copy_move&&) noexcept = default; 00187 }; 00188 00189 template<typename _Tag> 00190 struct _Enable_copy_move<true, false, false, true, _Tag> 00191 { 00192 constexpr _Enable_copy_move() noexcept = default; 00193 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default; 00194 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00195 _Enable_copy_move& 00196 operator=(_Enable_copy_move const&) noexcept = delete; 00197 _Enable_copy_move& 00198 operator=(_Enable_copy_move&&) noexcept = default; 00199 }; 00200 00201 template<typename _Tag> 00202 struct _Enable_copy_move<false, false, false, true, _Tag> 00203 { 00204 constexpr _Enable_copy_move() noexcept = default; 00205 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00206 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00207 _Enable_copy_move& 00208 operator=(_Enable_copy_move const&) noexcept = delete; 00209 _Enable_copy_move& 00210 operator=(_Enable_copy_move&&) noexcept = default; 00211 }; 00212 00213 template<typename _Tag> 00214 struct _Enable_copy_move<true, true, true, false, _Tag> 00215 { 00216 constexpr _Enable_copy_move() noexcept = default; 00217 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default; 00218 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default; 00219 _Enable_copy_move& 00220 operator=(_Enable_copy_move const&) noexcept = default; 00221 _Enable_copy_move& 00222 operator=(_Enable_copy_move&&) noexcept = delete; 00223 }; 00224 00225 template<typename _Tag> 00226 struct _Enable_copy_move<false, true, true, false, _Tag> 00227 { 00228 constexpr _Enable_copy_move() noexcept = default; 00229 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00230 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default; 00231 _Enable_copy_move& 00232 operator=(_Enable_copy_move const&) noexcept = default; 00233 _Enable_copy_move& 00234 operator=(_Enable_copy_move&&) noexcept = delete; 00235 }; 00236 00237 template<typename _Tag> 00238 struct _Enable_copy_move<true, false, true, false, _Tag> 00239 { 00240 constexpr _Enable_copy_move() noexcept = default; 00241 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default; 00242 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default; 00243 _Enable_copy_move& 00244 operator=(_Enable_copy_move const&) noexcept = delete; 00245 _Enable_copy_move& 00246 operator=(_Enable_copy_move&&) noexcept = delete; 00247 }; 00248 00249 template<typename _Tag> 00250 struct _Enable_copy_move<false, false, true, false, _Tag> 00251 { 00252 constexpr _Enable_copy_move() noexcept = default; 00253 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00254 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = default; 00255 _Enable_copy_move& 00256 operator=(_Enable_copy_move const&) noexcept = delete; 00257 _Enable_copy_move& 00258 operator=(_Enable_copy_move&&) noexcept = delete; 00259 }; 00260 00261 template<typename _Tag> 00262 struct _Enable_copy_move<true, true, false, false, _Tag> 00263 { 00264 constexpr _Enable_copy_move() noexcept = default; 00265 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default; 00266 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00267 _Enable_copy_move& 00268 operator=(_Enable_copy_move const&) noexcept = default; 00269 _Enable_copy_move& 00270 operator=(_Enable_copy_move&&) noexcept = delete; 00271 }; 00272 00273 template<typename _Tag> 00274 struct _Enable_copy_move<false, true, false, false, _Tag> 00275 { 00276 constexpr _Enable_copy_move() noexcept = default; 00277 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00278 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00279 _Enable_copy_move& 00280 operator=(_Enable_copy_move const&) noexcept = default; 00281 _Enable_copy_move& 00282 operator=(_Enable_copy_move&&) noexcept = delete; 00283 }; 00284 00285 template<typename _Tag> 00286 struct _Enable_copy_move<true, false, false, false, _Tag> 00287 { 00288 constexpr _Enable_copy_move() noexcept = default; 00289 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = default; 00290 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00291 _Enable_copy_move& 00292 operator=(_Enable_copy_move const&) noexcept = delete; 00293 _Enable_copy_move& 00294 operator=(_Enable_copy_move&&) noexcept = delete; 00295 }; 00296 00297 template<typename _Tag> 00298 struct _Enable_copy_move<false, false, false, false, _Tag> 00299 { 00300 constexpr _Enable_copy_move() noexcept = default; 00301 constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept = delete; 00302 constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept = delete; 00303 _Enable_copy_move& 00304 operator=(_Enable_copy_move const&) noexcept = delete; 00305 _Enable_copy_move& 00306 operator=(_Enable_copy_move&&) noexcept = delete; 00307 }; 00308 00309 _GLIBCXX_END_NAMESPACE_VERSION 00310 } // namespace std 00311 00312 #endif // _ENABLE_SPECIAL_MEMBERS_H