File indexing completed on 2025-01-18 09:53:30
0001
0002
0003
0004
0005
0006
0007
0008
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
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifndef BOOST_BASE_FROM_MEMBER_MAX_ARITY
0037 #define BOOST_BASE_FROM_MEMBER_MAX_ARITY 10
0038 #endif
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
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
0058
0059 namespace boost
0060 {
0061
0062 namespace detail
0063 {
0064
0065
0066
0067
0068
0069
0070
0071
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 };
0080
0081
0082
0083
0084
0085
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
0095
0096
0097
0098
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 }
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
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)... )) )
0139 : member( static_cast<T&&>(x)... )
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 };
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 };
0165
0166 }
0167
0168
0169
0170 #undef BOOST_PRIVATE_CTR_DEF
0171
0172
0173 #endif