Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:30

0001 //  boost utility/base_from_member.hpp header file  --------------------------//
0002 
0003 //  Copyright 2001, 2003, 2004, 2012 Daryle Walker.  Use, modification, and
0004 //  distribution are subject to the Boost Software License, Version 1.0.  (See
0005 //  accompanying file LICENSE_1_0.txt or a copy at
0006 //  <http://www.boost.org/LICENSE_1_0.txt>.)
0007 
0008 //  See <http://www.boost.org/libs/utility/> for the library's home page.
0009 
0010 #ifndef BOOST_UTILITY_BASE_FROM_MEMBER_HPP
0011 #define BOOST_UTILITY_BASE_FROM_MEMBER_HPP
0012 
0013 #include <boost/config.hpp>
0014 #include <boost/preprocessor/arithmetic/inc.hpp>
0015 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0016 #include <boost/preprocessor/repetition/enum_params.hpp>
0017 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
0018 #include <boost/type_traits/is_same.hpp>
0019 #include <boost/type_traits/remove_cv.hpp>
0020 #include <boost/type_traits/remove_reference.hpp>
0021 #include <boost/utility/enable_if.hpp>
0022 
0023 
0024 //  Base-from-member arity configuration macro  ------------------------------//
0025 
0026 // The following macro determines how many arguments will be in the largest
0027 // constructor template of base_from_member.  Constructor templates will be
0028 // generated from one argument to this maximum.  Code from other files can read
0029 // this number if they need to always match the exact maximum base_from_member
0030 // uses.  The maximum constructor length can be changed by overriding the
0031 // #defined constant.  Make sure to apply the override, if any, for all source
0032 // files during project compiling for consistency.
0033 
0034 // Contributed by Jonathan Turkanis
0035 
0036 #ifndef BOOST_BASE_FROM_MEMBER_MAX_ARITY
0037 #define BOOST_BASE_FROM_MEMBER_MAX_ARITY  10
0038 #endif
0039 
0040 
0041 //  An iteration of a constructor template for base_from_member  -------------//
0042 
0043 // A macro that should expand to:
0044 //     template < typename T1, ..., typename Tn >
0045 //     base_from_member( T1 x1, ..., Tn xn )
0046 //         : member( x1, ..., xn )
0047 //         {}
0048 // This macro should only persist within this file.
0049 
0050 #ifndef BOOST_UTILITY_DOCS
0051 #define BOOST_PRIVATE_CTR_DEF( z, n, data )                   \
0052     template < BOOST_PP_ENUM_PARAMS(n, typename T) >          \
0053     base_from_member( BOOST_PP_ENUM_BINARY_PARAMS(n, T, x) )  \
0054         : member( BOOST_PP_ENUM_PARAMS(n, x) )                \
0055         {}                                                    \
0056     /**/
0057 #endif // BOOST_UTILITY_DOCS
0058 
0059 namespace boost
0060 {
0061 
0062 namespace detail
0063 {
0064 
0065 //  Type-unmarking class template  -------------------------------------------//
0066 
0067 // Type-trait to get the raw type, i.e. the type without top-level reference nor
0068 // cv-qualification, from a type expression.  Mainly for function arguments, any
0069 // reference part is stripped first.
0070 
0071 // Contributed by Daryle Walker
0072 
0073 template < typename T >
0074 struct remove_cv_ref
0075 {
0076     typedef typename ::boost::remove_cv<typename
0077      ::boost::remove_reference<T>::type>::type  type;
0078 
0079 };  // boost::detail::remove_cv_ref
0080 
0081 //  Unmarked-type comparison class template  ---------------------------------//
0082 
0083 // Type-trait to check if two type expressions have the same raw type.
0084 
0085 // Contributed by Daryle Walker, based on a work-around by Luc Danton
0086 
0087 template < typename T, typename U >
0088 struct is_related
0089     : public ::boost::is_same<
0090      typename ::boost::detail::remove_cv_ref<T>::type,
0091      typename ::boost::detail::remove_cv_ref<U>::type >
0092 {};
0093 
0094 //  Enable-if-on-unidentical-unmarked-type class template  -------------------//
0095 
0096 // Enable-if on the first two type expressions NOT having the same raw type.
0097 
0098 // Contributed by Daryle Walker, based on a work-around by Luc Danton
0099 
0100 #ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0101 template<typename ...T>
0102 struct enable_if_unrelated
0103     : public ::boost::enable_if_c<true>
0104 {};
0105 
0106 template<typename T, typename U, typename ...U2>
0107 struct enable_if_unrelated<T, U, U2...>
0108     : public ::boost::disable_if< ::boost::detail::is_related<T, U> >
0109 {};
0110 #endif
0111 
0112 }  // namespace boost::detail
0113 
0114 
0115 //  Base-from-member class template  -----------------------------------------//
0116 
0117 // Helper to initialize a base object so a derived class can use this
0118 // object in the initialization of another base class.  Used by
0119 // Dietmar Kuehl from ideas by Ron Klatcho to solve the problem of a
0120 // base class needing to be initialized by a member.
0121 
0122 // Contributed by Daryle Walker
0123 
0124 template < typename MemberType, int UniqueID = 0 >
0125 class base_from_member
0126 {
0127 protected:
0128     MemberType  member;
0129 
0130 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
0131     !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
0132     !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) && \
0133     !(defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 4))
0134     template <typename ...T, typename EnableIf = typename
0135      ::boost::detail::enable_if_unrelated<base_from_member, T...>::type>
0136     explicit BOOST_CONSTEXPR base_from_member( T&& ...x )
0137         BOOST_NOEXCEPT_IF( BOOST_NOEXCEPT_EXPR(::new ((void*) 0) MemberType(
0138          static_cast<T&&>(x)... )) )  // no std::is_nothrow_constructible...
0139         : member( static_cast<T&&>(x)... )     // ...nor std::forward needed
0140         {}
0141 #else
0142     base_from_member()
0143         : member()
0144         {}
0145 
0146     template < typename T0 > explicit base_from_member( T0 x0 ) : member( x0 ) {}
0147     BOOST_PP_REPEAT_FROM_TO( 2, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY),
0148      BOOST_PRIVATE_CTR_DEF, _ )
0149 #endif
0150 
0151 };  // boost::base_from_member
0152 
0153 template < typename MemberType, int UniqueID >
0154 class base_from_member<MemberType&, UniqueID>
0155 {
0156 protected:
0157     MemberType& member;
0158 
0159     explicit BOOST_CONSTEXPR base_from_member( MemberType& x )
0160         BOOST_NOEXCEPT
0161         : member( x )
0162         {}
0163 
0164 };  // boost::base_from_member
0165 
0166 }  // namespace boost
0167 
0168 
0169 // Undo any private macros
0170 #undef BOOST_PRIVATE_CTR_DEF
0171 
0172 
0173 #endif  // BOOST_UTILITY_BASE_FROM_MEMBER_HPP