libstdc++
enable_special_members.h
Go to the documentation of this file.
00001 // <bits/enable_special_members.h> -*- C++ -*-
00002 
00003 // Copyright (C) 2013-2015 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 /**
00040   * @brief A mixin helper to conditionally enable or disable the default
00041   * constructor.
00042   * @sa _Enable_special_members
00043   */
00044 template<bool _Switch, typename _Tag = void>
00045   struct _Enable_default_constructor { };
00046 
00047 
00048 /**
00049   * @brief A mixin helper to conditionally enable or disable the default
00050   * destructor.
00051   * @sa _Enable_special_members
00052   */
00053 template<bool _Switch, typename _Tag = void>
00054   struct _Enable_destructor { };
00055 
00056 /**
00057   * @brief A mixin helper to conditionally enable or disable the copy/move
00058   * special members.
00059   * @sa _Enable_special_members
00060   */
00061 template<bool _Copy, bool _CopyAssignment,
00062          bool _Move, bool _MoveAssignment,
00063          typename _Tag = void>
00064   struct _Enable_copy_move { };
00065 
00066 /**
00067   * @brief A mixin helper to conditionally enable or disable the special
00068   * members.
00069   *
00070   * The @c _Tag type parameter is to make mixin bases unique and thus avoid
00071   * ambiguities.
00072   */
00073 template<bool _Default, bool _Destructor,
00074          bool _Copy, bool _CopyAssignment,
00075          bool _Move, bool _MoveAssignment,
00076          typename _Tag = void>
00077   struct _Enable_special_members
00078   : private _Enable_default_constructor<_Default, _Tag>,
00079     private _Enable_destructor<_Destructor, _Tag>,
00080     private _Enable_copy_move<_Copy, _CopyAssignment,
00081                               _Move, _MoveAssignment,
00082                               _Tag>
00083   { };
00084 
00085 // Boilerplate follows.
00086 
00087 template<typename _Tag>
00088   struct _Enable_default_constructor<false, _Tag>
00089   { constexpr _Enable_default_constructor() noexcept = delete; };
00090 
00091 template<typename _Tag>
00092   struct _Enable_destructor<false, _Tag>
00093   { ~_Enable_destructor() noexcept = delete; };
00094 
00095 template<typename _Tag>
00096   struct _Enable_copy_move<false, true, true, true, _Tag>
00097   {
00098     constexpr _Enable_copy_move() noexcept                          = default;
00099     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00100     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = default;
00101     _Enable_copy_move&
00102     operator=(_Enable_copy_move const&) noexcept                    = default;
00103     _Enable_copy_move&
00104     operator=(_Enable_copy_move&&) noexcept                         = default;
00105   };
00106 
00107 template<typename _Tag>
00108   struct _Enable_copy_move<true, false, true, true, _Tag>
00109   {
00110     constexpr _Enable_copy_move() noexcept                          = default;
00111     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = default;
00112     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = default;
00113     _Enable_copy_move&
00114     operator=(_Enable_copy_move const&) noexcept                    = delete;
00115     _Enable_copy_move&
00116     operator=(_Enable_copy_move&&) noexcept                         = default;
00117   };
00118 
00119 template<typename _Tag>
00120   struct _Enable_copy_move<false, false, true, true, _Tag>
00121   {
00122     constexpr _Enable_copy_move() noexcept                          = default;
00123     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00124     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = default;
00125     _Enable_copy_move&
00126     operator=(_Enable_copy_move const&) noexcept                    = delete;
00127     _Enable_copy_move&
00128     operator=(_Enable_copy_move&&) noexcept                         = default;
00129   };
00130 
00131 template<typename _Tag>
00132   struct _Enable_copy_move<true, true, false, true, _Tag>
00133   {
00134     constexpr _Enable_copy_move() noexcept                          = default;
00135     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = default;
00136     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00137     _Enable_copy_move&
00138     operator=(_Enable_copy_move const&) noexcept                    = default;
00139     _Enable_copy_move&
00140     operator=(_Enable_copy_move&&) noexcept                         = default;
00141   };
00142 
00143 template<typename _Tag>
00144   struct _Enable_copy_move<false, true, false, true, _Tag>
00145   {
00146     constexpr _Enable_copy_move() noexcept                          = default;
00147     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00148     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00149     _Enable_copy_move&
00150     operator=(_Enable_copy_move const&) noexcept                    = default;
00151     _Enable_copy_move&
00152     operator=(_Enable_copy_move&&) noexcept                         = default;
00153   };
00154 
00155 template<typename _Tag>
00156   struct _Enable_copy_move<true, false, false, true, _Tag>
00157   {
00158     constexpr _Enable_copy_move() noexcept                          = default;
00159     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = default;
00160     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00161     _Enable_copy_move&
00162     operator=(_Enable_copy_move const&) noexcept                    = delete;
00163     _Enable_copy_move&
00164     operator=(_Enable_copy_move&&) noexcept                         = default;
00165   };
00166 
00167 template<typename _Tag>
00168   struct _Enable_copy_move<false, false, false, true, _Tag>
00169   {
00170     constexpr _Enable_copy_move() noexcept                          = default;
00171     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00172     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00173     _Enable_copy_move&
00174     operator=(_Enable_copy_move const&) noexcept                    = delete;
00175     _Enable_copy_move&
00176     operator=(_Enable_copy_move&&) noexcept                         = default;
00177   };
00178 
00179 template<typename _Tag>
00180   struct _Enable_copy_move<true, true, true, false, _Tag>
00181   {
00182     constexpr _Enable_copy_move() noexcept                          = default;
00183     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = default;
00184     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = default;
00185     _Enable_copy_move&
00186     operator=(_Enable_copy_move const&) noexcept                    = default;
00187     _Enable_copy_move&
00188     operator=(_Enable_copy_move&&) noexcept                         = delete;
00189   };
00190 
00191 template<typename _Tag>
00192   struct _Enable_copy_move<false, true, true, false, _Tag>
00193   {
00194     constexpr _Enable_copy_move() noexcept                          = default;
00195     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00196     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = default;
00197     _Enable_copy_move&
00198     operator=(_Enable_copy_move const&) noexcept                    = default;
00199     _Enable_copy_move&
00200     operator=(_Enable_copy_move&&) noexcept                         = delete;
00201   };
00202 
00203 template<typename _Tag>
00204   struct _Enable_copy_move<true, false, true, false, _Tag>
00205   {
00206     constexpr _Enable_copy_move() noexcept                          = default;
00207     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = default;
00208     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = default;
00209     _Enable_copy_move&
00210     operator=(_Enable_copy_move const&) noexcept                    = delete;
00211     _Enable_copy_move&
00212     operator=(_Enable_copy_move&&) noexcept                         = delete;
00213   };
00214 
00215 template<typename _Tag>
00216   struct _Enable_copy_move<false, false, true, false, _Tag>
00217   {
00218     constexpr _Enable_copy_move() noexcept                          = default;
00219     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00220     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = default;
00221     _Enable_copy_move&
00222     operator=(_Enable_copy_move const&) noexcept                    = delete;
00223     _Enable_copy_move&
00224     operator=(_Enable_copy_move&&) noexcept                         = delete;
00225   };
00226 
00227 template<typename _Tag>
00228   struct _Enable_copy_move<true, true, false, false, _Tag>
00229   {
00230     constexpr _Enable_copy_move() noexcept                          = default;
00231     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = default;
00232     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00233     _Enable_copy_move&
00234     operator=(_Enable_copy_move const&) noexcept                    = default;
00235     _Enable_copy_move&
00236     operator=(_Enable_copy_move&&) noexcept                         = delete;
00237   };
00238 
00239 template<typename _Tag>
00240   struct _Enable_copy_move<false, true, false, false, _Tag>
00241   {
00242     constexpr _Enable_copy_move() noexcept                          = default;
00243     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00244     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00245     _Enable_copy_move&
00246     operator=(_Enable_copy_move const&) noexcept                    = default;
00247     _Enable_copy_move&
00248     operator=(_Enable_copy_move&&) noexcept                         = delete;
00249   };
00250 
00251 template<typename _Tag>
00252   struct _Enable_copy_move<true, false, false, false, _Tag>
00253   {
00254     constexpr _Enable_copy_move() noexcept                          = default;
00255     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = default;
00256     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00257     _Enable_copy_move&
00258     operator=(_Enable_copy_move const&) noexcept                    = delete;
00259     _Enable_copy_move&
00260     operator=(_Enable_copy_move&&) noexcept                         = delete;
00261   };
00262 
00263 template<typename _Tag>
00264   struct _Enable_copy_move<false, false, false, false, _Tag>
00265   {
00266     constexpr _Enable_copy_move() noexcept                          = default;
00267     constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
00268     constexpr _Enable_copy_move(_Enable_copy_move&&) noexcept       = delete;
00269     _Enable_copy_move&
00270     operator=(_Enable_copy_move const&) noexcept                    = delete;
00271     _Enable_copy_move&
00272     operator=(_Enable_copy_move&&) noexcept                         = delete;
00273   };
00274 
00275 _GLIBCXX_END_NAMESPACE_VERSION
00276 } // namespace std
00277 
00278 #endif // _ENABLE_SPECIAL_MEMBERS_H