Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 08:28:16

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 #   include <boost/mpl/aux_/value_wknd.hpp>
0026 #   include <boost/mpl/int.hpp>
0027 #   include <boost/mpl/iter_fold.hpp>
0028 #   include <boost/mpl/next.hpp>
0029 #   include <boost/mpl/deref.hpp>
0030 #   include <boost/mpl/pair.hpp>
0031 #   include <boost/mpl/protect.hpp>
0032 
0033 
0034 namespace boost {
0035 namespace detail { namespace variant {
0036 
0037 ///////////////////////////////////////////////////////////////////////////////
0038 // (detail) support to simulate standard overload resolution rules
0039 //
0040 // The below initializers allows variant to follow standard overload
0041 // resolution rules over the specified set of bounded types.
0042 //
0043 // On compilers where using declarations in class templates can correctly
0044 // avoid name hiding, use an optimal solution based on the variant's typelist.
0045 //
0046 // Otherwise, use a preprocessor workaround based on knowledge of the fixed
0047 // size of the variant's psuedo-variadic template parameter list.
0048 //
0049 
0050 // (detail) quoted metafunction make_initializer_node
0051 //
0052 // Exposes a pair whose first type is a node in the initializer hierarchy.
0053 //
0054 struct make_initializer_node
0055 {
0056     template <typename BaseIndexPair, typename Iterator>
0057     struct apply
0058     {
0059     private: // helpers, for metafunction result (below)
0060 
0061         typedef typename BaseIndexPair::first
0062             base;
0063         typedef typename BaseIndexPair::second
0064             index;
0065 
0066         class initializer_node
0067             : public base
0068         {
0069         private: // helpers, for static functions (below)
0070 
0071             typedef typename mpl::deref<Iterator>::type
0072                 recursive_enabled_T;
0073             typedef typename unwrap_recursive<recursive_enabled_T>::type
0074                 public_T;
0075 
0076             typedef boost::is_reference<public_T> 
0077                 is_reference_content_t;
0078 
0079             typedef typename boost::mpl::if_<is_reference_content_t, public_T, const public_T& >::type 
0080                 param_T;
0081 
0082             template <class T> struct disable_overload{};
0083 
0084             typedef typename boost::mpl::if_<is_reference_content_t, disable_overload<public_T>, public_T&& >::type 
0085                 param2_T;
0086 
0087         public: // static functions
0088 
0089             using base::initialize;
0090 
0091             static int initialize(void* dest, param_T operand)
0092             {
0093                 typedef typename boost::detail::make_reference_content<
0094                       recursive_enabled_T
0095                     >::type internal_T;
0096 
0097                 new(dest) internal_T(operand);
0098                 return BOOST_MPL_AUX_VALUE_WKND(index)::value; // which
0099             }
0100 
0101             static int initialize(void* dest, param2_T operand)
0102             {
0103                 // This assert must newer trigger, because all the reference contents are
0104                 // handled by the initilize(void* dest, param_T operand) function above
0105                 BOOST_ASSERT(!is_reference_content_t::value);
0106 
0107                 typedef typename boost::mpl::if_<is_reference_content_t, param2_T, recursive_enabled_T>::type value_T;
0108                 new(dest) value_T( boost::detail::variant::move(operand) );
0109                 return BOOST_MPL_AUX_VALUE_WKND(index)::value; // which
0110             }
0111         };
0112 
0113         friend class initializer_node;
0114 
0115     public: // metafunction result
0116 
0117         typedef mpl::pair<
0118               initializer_node
0119             , typename mpl::next< index >::type
0120             > type;
0121 
0122     };
0123 };
0124 
0125 // (detail) class initializer_root
0126 //
0127 // Every level of the initializer hierarchy must expose the name
0128 // "initialize," so initializer_root provides a dummy function:
0129 //
0130 class initializer_root
0131 {
0132 public: // static functions
0133 
0134     static void initialize();
0135 
0136 };
0137 
0138 }} // namespace detail::variant
0139 } // namespace boost
0140 
0141 ///////////////////////////////////////////////////////////////////////////////
0142 // macro BOOST_VARIANT_AUX_INITIALIZER_T
0143 //
0144 // Given both the variant's typelist and a basename for forming the list of
0145 // bounded types (i.e., T becomes T1, T2, etc.), exposes the initializer
0146 // most appropriate to the current compiler.
0147 //
0148 
0149 #define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
0150     ::boost::mpl::iter_fold< \
0151           mpl_seq \
0152         , ::boost::mpl::pair< \
0153               ::boost::detail::variant::initializer_root \
0154             , ::boost::mpl::int_<0> \
0155             > \
0156         , ::boost::mpl::protect< \
0157               ::boost::detail::variant::make_initializer_node \
0158             > \
0159         >::type::first \
0160     /**/
0161 
0162 #endif // BOOST_VARIANT_DETAIL_INITIALIZER_HPP