Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //-----------------------------------------------------------------------------
0002 // boost variant/detail/initializer.hpp header file
0003 // See http://www.boost.org for updates, documentation, and revision history.
0004 //-----------------------------------------------------------------------------
0005 //
0006 // Copyright (c) 2002-2003
0007 // Eric Friedman, Itay Maman
0008 //
0009 // Distributed under the Boost Software License, Version 1.0. (See
0010 // accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
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 // (detail) support to simulate standard overload resolution rules
0045 //
0046 // The below initializers allows variant to follow standard overload
0047 // resolution rules over the specified set of bounded types.
0048 //
0049 // On compilers where using declarations in class templates can correctly
0050 // avoid name hiding, use an optimal solution based on the variant's typelist.
0051 //
0052 // Otherwise, use a preprocessor workaround based on knowledge of the fixed
0053 // size of the variant's psuedo-variadic template parameter list.
0054 //
0055 
0056 #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
0057 
0058 // (detail) quoted metafunction make_initializer_node
0059 //
0060 // Exposes a pair whose first type is a node in the initializer hierarchy.
0061 //
0062 struct make_initializer_node
0063 {
0064     template <typename BaseIndexPair, typename Iterator>
0065     struct apply
0066     {
0067     private: // helpers, for metafunction result (below)
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: // helpers, for static functions (below)
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: // static functions
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; // which
0112             }
0113 
0114 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0115             static int initialize(void* dest, param2_T operand)
0116             {
0117                 // This assert must newer trigger, because all the reference contents are
0118                 // handled by the initilize(void* dest, param_T operand) function above
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; // which
0124             }
0125 #endif
0126         };
0127 
0128         friend class initializer_node;
0129 
0130     public: // metafunction result
0131 
0132         typedef mpl::pair<
0133               initializer_node
0134             , typename mpl::next< index >::type
0135             > type;
0136 
0137     };
0138 };
0139 
0140 // (detail) class initializer_root
0141 //
0142 // Every level of the initializer hierarchy must expose the name
0143 // "initialize," so initializer_root provides a dummy function:
0144 //
0145 class initializer_root
0146 {
0147 public: // static functions
0148 
0149     static void initialize();
0150 
0151 };
0152 
0153 #else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
0154 
0155     // Obsolete. Remove.
0156     #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
0157           BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
0158     /**/
0159 
0160     // Obsolete. Remove.
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: // static functions
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); /*which*/ \
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 // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
0207 
0208 }} // namespace detail::variant
0209 } // namespace boost
0210 
0211 ///////////////////////////////////////////////////////////////////////////////
0212 // macro BOOST_VARIANT_AUX_INITIALIZER_T
0213 //
0214 // Given both the variant's typelist and a basename for forming the list of
0215 // bounded types (i.e., T becomes T1, T2, etc.), exposes the initializer
0216 // most appropriate to the current compiler.
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 // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
0235 
0236     // Obsolete. Remove.
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 // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
0248 
0249 #endif // BOOST_VARIANT_DETAIL_INITIALIZER_HPP