File indexing completed on 2025-01-18 09:53:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_VARIANT_DETAIL_INITIALIZER_HPP
0014 #define BOOST_VARIANT_DETAIL_INITIALIZER_HPP
0015
0016 #include <new> // for placement new
0017
0018 #include <boost/config.hpp>
0019
0020 #include <boost/call_traits.hpp>
0021 #include <boost/detail/reference_content.hpp>
0022 #include <boost/variant/recursive_wrapper_fwd.hpp>
0023 #include <boost/variant/detail/move.hpp>
0024
0025 #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
0026 # include <boost/mpl/aux_/value_wknd.hpp>
0027 # include <boost/mpl/int.hpp>
0028 # include <boost/mpl/iter_fold.hpp>
0029 # include <boost/mpl/next.hpp>
0030 # include <boost/mpl/deref.hpp>
0031 # include <boost/mpl/pair.hpp>
0032 # include <boost/mpl/protect.hpp>
0033 #else
0034 # include <boost/variant/variant_fwd.hpp>
0035 # include <boost/preprocessor/cat.hpp>
0036 # include <boost/preprocessor/enum.hpp>
0037 # include <boost/preprocessor/repeat.hpp>
0038 #endif
0039
0040 namespace boost {
0041 namespace detail { namespace variant {
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
0057
0058
0059
0060
0061
0062 struct make_initializer_node
0063 {
0064 template <typename BaseIndexPair, typename Iterator>
0065 struct apply
0066 {
0067 private:
0068
0069 typedef typename BaseIndexPair::first
0070 base;
0071 typedef typename BaseIndexPair::second
0072 index;
0073
0074 class initializer_node
0075 : public base
0076 {
0077 private:
0078
0079 typedef typename mpl::deref<Iterator>::type
0080 recursive_enabled_T;
0081 typedef typename unwrap_recursive<recursive_enabled_T>::type
0082 public_T;
0083
0084 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0085 typedef boost::is_reference<public_T>
0086 is_reference_content_t;
0087
0088 typedef typename boost::mpl::if_<is_reference_content_t, public_T, const public_T& >::type
0089 param_T;
0090
0091 template <class T> struct disable_overload{};
0092
0093 typedef typename boost::mpl::if_<is_reference_content_t, disable_overload<public_T>, public_T&& >::type
0094 param2_T;
0095 #else
0096 typedef typename call_traits<public_T>::param_type
0097 param_T;
0098 #endif
0099
0100 public:
0101
0102 using base::initialize;
0103
0104 static int initialize(void* dest, param_T operand)
0105 {
0106 typedef typename boost::detail::make_reference_content<
0107 recursive_enabled_T
0108 >::type internal_T;
0109
0110 new(dest) internal_T(operand);
0111 return BOOST_MPL_AUX_VALUE_WKND(index)::value;
0112 }
0113
0114 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0115 static int initialize(void* dest, param2_T operand)
0116 {
0117
0118
0119 BOOST_ASSERT(!is_reference_content_t::value);
0120
0121 typedef typename boost::mpl::if_<is_reference_content_t, param2_T, recursive_enabled_T>::type value_T;
0122 new(dest) value_T( boost::detail::variant::move(operand) );
0123 return BOOST_MPL_AUX_VALUE_WKND(index)::value;
0124 }
0125 #endif
0126 };
0127
0128 friend class initializer_node;
0129
0130 public:
0131
0132 typedef mpl::pair<
0133 initializer_node
0134 , typename mpl::next< index >::type
0135 > type;
0136
0137 };
0138 };
0139
0140
0141
0142
0143
0144
0145 class initializer_root
0146 {
0147 public:
0148
0149 static void initialize();
0150
0151 };
0152
0153 #else
0154
0155
0156 #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
0157 BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
0158
0159
0160
0161 #define BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
0162 typedef typename unwrap_recursive< \
0163 BOOST_PP_CAT(recursive_enabled_T,N) \
0164 >::type BOOST_PP_CAT(public_T,N); \
0165 typedef typename call_traits< \
0166 BOOST_PP_CAT(public_T,N) \
0167 >::param_type BOOST_PP_CAT(param_T,N); \
0168
0169
0170 template < BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) >
0171 struct preprocessor_list_initializer
0172 {
0173 public:
0174
0175 #define BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION(z,N,_) \
0176 typedef typename unwrap_recursive< \
0177 BOOST_PP_CAT(recursive_enabled_T,N) \
0178 >::type BOOST_PP_CAT(public_T,N); \
0179 typedef typename call_traits< \
0180 BOOST_PP_CAT(public_T,N) \
0181 >::param_type BOOST_PP_CAT(param_T,N); \
0182 static int initialize( \
0183 void* dest \
0184 , BOOST_PP_CAT(param_T,N) operand \
0185 ) \
0186 { \
0187 typedef typename boost::detail::make_reference_content< \
0188 BOOST_PP_CAT(recursive_enabled_T,N) \
0189 >::type internal_T; \
0190 \
0191 new(dest) internal_T(operand); \
0192 return (N); \
0193 } \
0194
0195
0196 BOOST_PP_REPEAT(
0197 BOOST_VARIANT_LIMIT_TYPES
0198 , BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
0199 , _
0200 )
0201
0202 #undef BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
0203
0204 };
0205
0206 #endif
0207
0208 }}
0209 }
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
0220
0221 #define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
0222 ::boost::mpl::iter_fold< \
0223 mpl_seq \
0224 , ::boost::mpl::pair< \
0225 ::boost::detail::variant::initializer_root \
0226 , ::boost::mpl::int_<0> \
0227 > \
0228 , ::boost::mpl::protect< \
0229 ::boost::detail::variant::make_initializer_node \
0230 > \
0231 >::type::first \
0232
0233
0234 #else
0235
0236
0237 #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
0238 BOOST_VARIANT_ENUM_PARAMS(typename_base) \
0239
0240
0241 #define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
0242 ::boost::detail::variant::preprocessor_list_initializer< \
0243 BOOST_VARIANT_ENUM_PARAMS(typename_base) \
0244 > \
0245
0246
0247 #endif
0248
0249 #endif