os/ossrv/ossrv_pub/boost_apis/boost/variant/detail/initializer.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/variant/detail/initializer.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,265 @@
     1.4 +//-----------------------------------------------------------------------------
     1.5 +// boost variant/detail/initializer.hpp header file
     1.6 +// See http://www.boost.org for updates, documentation, and revision history.
     1.7 +//-----------------------------------------------------------------------------
     1.8 +//
     1.9 +// Copyright (c) 2002-2003
    1.10 +// Eric Friedman, Itay Maman
    1.11 +//
    1.12 +// Distributed under the Boost Software License, Version 1.0. (See
    1.13 +// accompanying file LICENSE_1_0.txt or copy at
    1.14 +// http://www.boost.org/LICENSE_1_0.txt)
    1.15 +
    1.16 +#ifndef BOOST_VARIANT_DETAIL_INITIALIZER_HPP
    1.17 +#define BOOST_VARIANT_DETAIL_INITIALIZER_HPP
    1.18 +
    1.19 +#include <new> // for placement new
    1.20 +
    1.21 +#include "boost/config.hpp"
    1.22 +
    1.23 +#include "boost/call_traits.hpp"
    1.24 +#include "boost/detail/reference_content.hpp"
    1.25 +#include "boost/variant/recursive_wrapper_fwd.hpp"
    1.26 +
    1.27 +#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
    1.28 +#   include "boost/mpl/aux_/value_wknd.hpp"
    1.29 +#   include "boost/mpl/int.hpp"
    1.30 +#   include "boost/mpl/iter_fold.hpp"
    1.31 +#   include "boost/mpl/next.hpp"
    1.32 +#   include "boost/mpl/deref.hpp"
    1.33 +#   include "boost/mpl/pair.hpp"
    1.34 +#   include "boost/mpl/protect.hpp"
    1.35 +#else
    1.36 +#   include "boost/variant/variant_fwd.hpp"
    1.37 +#   include "boost/preprocessor/cat.hpp"
    1.38 +#   include "boost/preprocessor/enum.hpp"
    1.39 +#   include "boost/preprocessor/repeat.hpp"
    1.40 +#endif
    1.41 +
    1.42 +namespace boost {
    1.43 +namespace detail { namespace variant {
    1.44 +
    1.45 +///////////////////////////////////////////////////////////////////////////////
    1.46 +// (detail) support to simulate standard overload resolution rules
    1.47 +//
    1.48 +// The below initializers allows variant to follow standard overload
    1.49 +// resolution rules over the specified set of bounded types.
    1.50 +//
    1.51 +// On compilers where using declarations in class templates can correctly
    1.52 +// avoid name hiding, use an optimal solution based on the variant's typelist.
    1.53 +//
    1.54 +// Otherwise, use a preprocessor workaround based on knowledge of the fixed
    1.55 +// size of the variant's psuedo-variadic template parameter list.
    1.56 +//
    1.57 +
    1.58 +#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
    1.59 +
    1.60 +// (detail) quoted metafunction make_initializer_node
    1.61 +//
    1.62 +// Exposes a pair whose first type is a node in the initializer hierarchy.
    1.63 +//
    1.64 +struct make_initializer_node
    1.65 +{
    1.66 +    template <typename BaseIndexPair, typename Iterator>
    1.67 +    struct apply
    1.68 +    {
    1.69 +    private: // helpers, for metafunction result (below)
    1.70 +
    1.71 +        typedef typename BaseIndexPair::first
    1.72 +            base;
    1.73 +        typedef typename BaseIndexPair::second
    1.74 +            index;
    1.75 +
    1.76 +        class initializer_node
    1.77 +            : public base
    1.78 +        {
    1.79 +        private: // helpers, for static functions (below)
    1.80 +
    1.81 +            typedef typename mpl::deref<Iterator>::type
    1.82 +                recursive_enabled_T;
    1.83 +            typedef typename unwrap_recursive<recursive_enabled_T>::type
    1.84 +                public_T;
    1.85 +            typedef typename call_traits<public_T>::param_type
    1.86 +                param_T;
    1.87 +
    1.88 +        public: // static functions
    1.89 +
    1.90 +            using base::initialize;
    1.91 +
    1.92 +            static int initialize(void* dest, param_T operand)
    1.93 +            {
    1.94 +                typedef typename boost::detail::make_reference_content<
    1.95 +                      recursive_enabled_T
    1.96 +                    >::type internal_T;
    1.97 +
    1.98 +                new(dest) internal_T(operand);
    1.99 +                return BOOST_MPL_AUX_VALUE_WKND(index)::value; // which
   1.100 +            }
   1.101 +
   1.102 +        };
   1.103 +
   1.104 +        friend class initializer_node;
   1.105 +
   1.106 +    public: // metafunction result
   1.107 +
   1.108 +        typedef mpl::pair<
   1.109 +              initializer_node
   1.110 +            , typename mpl::next< index >::type
   1.111 +            > type;
   1.112 +
   1.113 +    };
   1.114 +};
   1.115 +
   1.116 +// (detail) class initializer_root
   1.117 +//
   1.118 +// Every level of the initializer hierarchy must expose the name
   1.119 +// "initialize," so initializer_root provides a dummy function:
   1.120 +//
   1.121 +class initializer_root
   1.122 +{
   1.123 +public: // static functions
   1.124 +
   1.125 +    static void initialize();
   1.126 +
   1.127 +};
   1.128 +
   1.129 +#else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
   1.130 +
   1.131 +#   if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) 
   1.132 +
   1.133 +    #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
   1.134 +          BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
   1.135 +    /**/
   1.136 +
   1.137 +    #define BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
   1.138 +        typedef typename unwrap_recursive< \
   1.139 +              BOOST_PP_CAT(recursive_enabled_T,N) \
   1.140 +            >::type BOOST_PP_CAT(public_T,N); \
   1.141 +        typedef typename call_traits< \
   1.142 +              BOOST_PP_CAT(public_T,N) \
   1.143 +            >::param_type BOOST_PP_CAT(param_T,N); \
   1.144 +    /**/
   1.145 +
   1.146 +#   else // MSVC7 and below
   1.147 +
   1.148 +    #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
   1.149 +          BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
   1.150 +        , BOOST_VARIANT_ENUM_PARAMS(typename param_T) \
   1.151 +    /**/
   1.152 +
   1.153 +    #define BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
   1.154 +    /**/
   1.155 +
   1.156 +#   endif // MSVC7 and below workaround
   1.157 +
   1.158 +template < BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS >
   1.159 +struct preprocessor_list_initializer
   1.160 +{
   1.161 +public: // static functions
   1.162 +
   1.163 +    #define BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION(z,N,_) \
   1.164 +        BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
   1.165 +        static int initialize( \
   1.166 +              void* dest \
   1.167 +            , BOOST_PP_CAT(param_T,N) operand \
   1.168 +            ) \
   1.169 +        { \
   1.170 +            typedef typename boost::detail::make_reference_content< \
   1.171 +                  BOOST_PP_CAT(recursive_enabled_T,N) \
   1.172 +                >::type internal_T; \
   1.173 +            \
   1.174 +            new(dest) internal_T(operand); \
   1.175 +            return (N); /*which*/ \
   1.176 +        } \
   1.177 +        /**/
   1.178 +
   1.179 +    BOOST_PP_REPEAT(
   1.180 +          BOOST_VARIANT_LIMIT_TYPES
   1.181 +        , BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
   1.182 +        , _
   1.183 +        )
   1.184 +
   1.185 +    #undef BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
   1.186 +
   1.187 +};
   1.188 +
   1.189 +#   if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
   1.190 +
   1.191 +#if !defined(BOOST_VARIANT_AUX_ECHO)
   1.192 +#   define BOOST_VARIANT_AUX_ECHO(z,N,token) token
   1.193 +#endif
   1.194 +
   1.195 +template <>
   1.196 +struct preprocessor_list_initializer<
   1.197 +      BOOST_PP_ENUM(BOOST_VARIANT_LIMIT_TYPES, BOOST_VARIANT_AUX_ECHO, int)
   1.198 +    , BOOST_PP_ENUM(BOOST_VARIANT_LIMIT_TYPES, BOOST_VARIANT_AUX_ECHO, const int)
   1.199 +    >
   1.200 +{
   1.201 +};
   1.202 +
   1.203 +#   endif // BOOST_MPL_CFG_MSVC_60_ETI_BUG workaround
   1.204 +
   1.205 +#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
   1.206 +
   1.207 +}} // namespace detail::variant
   1.208 +} // namespace boost
   1.209 +
   1.210 +///////////////////////////////////////////////////////////////////////////////
   1.211 +// macro BOOST_VARIANT_AUX_INITIALIZER_T
   1.212 +//
   1.213 +// Given both the variant's typelist and a basename for forming the list of
   1.214 +// bounded types (i.e., T becomes T1, T2, etc.), exposes the initializer
   1.215 +// most appropriate to the current compiler.
   1.216 +//
   1.217 +
   1.218 +#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
   1.219 +
   1.220 +#define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
   1.221 +    ::boost::mpl::iter_fold< \
   1.222 +          mpl_seq \
   1.223 +        , ::boost::mpl::pair< \
   1.224 +              ::boost::detail::variant::initializer_root \
   1.225 +            , ::boost::mpl::int_<0> \
   1.226 +            > \
   1.227 +        , ::boost::mpl::protect< \
   1.228 +              ::boost::detail::variant::make_initializer_node \
   1.229 +            > \
   1.230 +        >::type::first \
   1.231 +    /**/
   1.232 +
   1.233 +#else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
   1.234 +
   1.235 +#   if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
   1.236 +
   1.237 +    #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
   1.238 +          BOOST_VARIANT_ENUM_PARAMS(typename_base) \
   1.239 +        /**/
   1.240 +
   1.241 +#   else // MSVC7 and below
   1.242 +
   1.243 +    #define BOOST_VARIANT_AUX_PP_INITIALIZER_ENUM_PARAM_TYPE(z,N,T) \
   1.244 +        ::boost::call_traits< \
   1.245 +              ::boost::unwrap_recursive<BOOST_PP_CAT(T,N)>::type \
   1.246 +            >::param_type \
   1.247 +        /**/
   1.248 +
   1.249 +    #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
   1.250 +          BOOST_VARIANT_ENUM_PARAMS(typename_base) \
   1.251 +        , BOOST_PP_ENUM( \
   1.252 +              BOOST_VARIANT_LIMIT_TYPES \
   1.253 +            , BOOST_VARIANT_AUX_PP_INITIALIZER_ENUM_PARAM_TYPE \
   1.254 +            , typename_base \
   1.255 +            ) \
   1.256 +        /**/
   1.257 +
   1.258 +#   endif // MSVC7 workaround
   1.259 +
   1.260 +#define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
   1.261 +    ::boost::detail::variant::preprocessor_list_initializer< \
   1.262 +          BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
   1.263 +        > \
   1.264 +    /**/
   1.265 +
   1.266 +#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
   1.267 +
   1.268 +#endif // BOOST_VARIANT_DETAIL_INITIALIZER_HPP