Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:54

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 #if !defined(BOOST_SPIRIT_EXTENDED_VARIANT_AUGUST_6_2011_0859AM)
0008 #define BOOST_SPIRIT_EXTENDED_VARIANT_AUGUST_6_2011_0859AM
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/variant.hpp>
0015 #include <boost/mpl/limits/list.hpp>
0016 #include <boost/preprocessor/repetition/enum_params.hpp>
0017 #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
0018 
0019 #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
0020 #define BOOST_SPIRIT_EXTENDED_VARIANT_LIMIT_TYPES BOOST_MPL_LIMIT_LIST_SIZE
0021 #else
0022 #define BOOST_SPIRIT_EXTENDED_VARIANT_LIMIT_TYPES BOOST_VARIANT_LIMIT_TYPES
0023 #endif
0024 
0025 #define BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(T)                          \
0026     BOOST_PP_ENUM_PARAMS(BOOST_SPIRIT_EXTENDED_VARIANT_LIMIT_TYPES, T)        \
0027     /**/
0028 
0029 ///////////////////////////////////////////////////////////////////////////////
0030 namespace boost { namespace spirit
0031 {
0032 #if defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
0033     template <
0034         BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
0035             BOOST_SPIRIT_EXTENDED_VARIANT_LIMIT_TYPES,
0036             typename T, boost::detail::variant::void_)
0037             // We should not be depending on detail::variant::void_
0038             // but I'm not sure if this can fixed. Any other way is
0039             // clumsy at best.
0040         >
0041 #else
0042     template <typename... Types>
0043 #endif
0044     struct extended_variant
0045     {
0046         // tell spirit that this is an adapted variant
0047         struct adapted_variant_tag;
0048 
0049 #if defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
0050         typedef boost::variant<
0051             BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(T)>
0052         variant_type;
0053         typedef typename variant_type::types types;
0054 
0055         typedef extended_variant<
0056             BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(T)
0057         > base_type;
0058 #else
0059         typedef boost::variant<Types...> variant_type;
0060         typedef typename variant_type::types types;
0061         typedef extended_variant<Types...> base_type;
0062 #endif
0063 
0064         extended_variant() : var() {}
0065 
0066         template <typename T>
0067         extended_variant(T const& var)
0068             : var(var) {}
0069 
0070         template <typename T>
0071         extended_variant(T& var)
0072             : var(var) {}
0073 
0074         template <typename F>
0075         typename F::result_type apply_visitor(F const& v)
0076         {
0077             return var.apply_visitor(v);
0078         }
0079 
0080         template <typename F>
0081         typename F::result_type apply_visitor(F const& v) const
0082         {
0083             return var.apply_visitor(v);
0084         }
0085 
0086         template <typename F>
0087         typename F::result_type apply_visitor(F& v)
0088         {
0089             return var.apply_visitor(v);
0090         }
0091 
0092         template <typename F>
0093         typename F::result_type apply_visitor(F& v) const
0094         {
0095             return var.apply_visitor(v);
0096         }
0097 
0098         variant_type const& get() const
0099         {
0100             return var;
0101         }
0102 
0103         variant_type& get()
0104         {
0105             return var;
0106         }
0107         
0108         void swap(extended_variant& rhs) BOOST_NOEXCEPT
0109         {
0110             var.swap(rhs.var);
0111         }
0112 
0113         variant_type var;
0114     };
0115 }}
0116 
0117 namespace boost
0118 {
0119 #if defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
0120     template <typename T, BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(typename T)>
0121     inline T const&
0122     get(boost::spirit::extended_variant<
0123         BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(T)> const& x)
0124     {
0125         return boost::get<T>(x.get());
0126     }
0127 
0128     template <typename T, BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(typename T)>
0129     inline T&
0130     get(boost::spirit::extended_variant<
0131         BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(T)>& x)
0132     {
0133         return boost::get<T>(x.get());
0134     }
0135 
0136     template <typename T, BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(typename T)>
0137     inline T const*
0138     get(boost::spirit::extended_variant<
0139         BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(T)> const* x)
0140     {
0141         return boost::get<T>(&x->get());
0142     }
0143 
0144     template <typename T, BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(typename T)>
0145     inline T*
0146     get(boost::spirit::extended_variant<
0147         BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS(T)>* x)
0148     {
0149         return boost::get<T>(&x->get());
0150     }
0151 #else
0152     template <typename T, typename... Types>
0153     inline T const&
0154     get(boost::spirit::extended_variant<Types...> const& x)
0155     {
0156         return boost::get<T>(x.get());
0157     }
0158 
0159     template <typename T, typename... Types>
0160     inline T&
0161     get(boost::spirit::extended_variant<Types...>& x)
0162     {
0163         return boost::get<T>(x.get());
0164     }
0165 
0166     template <typename T, typename... Types>
0167     inline T const*
0168     get(boost::spirit::extended_variant<Types...> const* x)
0169     {
0170         return boost::get<T>(&x->get());
0171     }
0172 
0173     template <typename T, typename... Types>
0174     inline T*
0175     get(boost::spirit::extended_variant<Types...>* x)
0176     {
0177         return boost::get<T>(&x->get());
0178     }
0179 #endif
0180 }
0181 
0182 #undef BOOST_SPIRIT_EXTENDED_VARIANT_ENUM_PARAMS
0183 #undef BOOST_SPIRIT_EXTENDED_VARIANT_LIMIT_TYPES
0184 
0185 #endif