sl@0: //----------------------------------------------------------------------------- sl@0: // boost variant/variant_fwd.hpp header file sl@0: // See http://www.boost.org for updates, documentation, and revision history. sl@0: //----------------------------------------------------------------------------- sl@0: // sl@0: // Copyright (c) 2003 sl@0: // Eric Friedman, Itay Maman sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: #ifndef BOOST_VARIANT_VARIANT_FWD_HPP sl@0: #define BOOST_VARIANT_VARIANT_FWD_HPP sl@0: sl@0: #include "boost/variant/detail/config.hpp" sl@0: sl@0: #include "boost/blank_fwd.hpp" sl@0: #include "boost/mpl/arg.hpp" sl@0: #include "boost/mpl/limits/arity.hpp" sl@0: #include "boost/mpl/aux_/na.hpp" sl@0: #include "boost/preprocessor/cat.hpp" sl@0: #include "boost/preprocessor/enum.hpp" sl@0: #include "boost/preprocessor/enum_params.hpp" sl@0: #include "boost/preprocessor/enum_shifted_params.hpp" sl@0: #include "boost/preprocessor/repeat.hpp" sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // macro BOOST_VARIANT_LIMIT_TYPES sl@0: // sl@0: // Implementation-defined preprocessor symbol describing the actual sl@0: // length of variant's pseudo-variadic template parameter list. sl@0: // sl@0: #include "boost/mpl/limits/list.hpp" sl@0: #define BOOST_VARIANT_LIMIT_TYPES \ sl@0: BOOST_MPL_LIMIT_LIST_SIZE sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // macro BOOST_VARIANT_NO_REFERENCE_SUPPORT sl@0: // sl@0: // Defined if variant does not support references as bounded types. sl@0: // sl@0: #if defined(BOOST_VARIANT_AUX_BROKEN_CONSTRUCTOR_TEMPLATE_ORDERING) \ sl@0: && !defined(BOOST_VARIANT_AUX_HAS_CONSTRUCTOR_TEMPLATE_ORDERING_SFINAE_WKND) \ sl@0: && !defined(BOOST_VARIANT_NO_REFERENCE_SUPPORT) sl@0: # define BOOST_VARIANT_NO_REFERENCE_SUPPORT sl@0: #endif sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // macro BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT sl@0: // sl@0: // Defined if variant does not support make_variant_over (see below). sl@0: // sl@0: #if defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE) sl@0: # define BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT sl@0: #endif sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT sl@0: // sl@0: // Defined if make_recursive_variant cannot be supported as documented. sl@0: // sl@0: // Note: Currently, MPL lambda facility is used as workaround if defined, and sl@0: // so only types declared w/ MPL lambda workarounds will work. sl@0: // sl@0: sl@0: #include "boost/variant/detail/substitute_fwd.hpp" sl@0: sl@0: #if defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE) \ sl@0: && !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT) sl@0: # define BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT sl@0: #endif sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // macro BOOST_VARIANT_RECURSIVE_VARIANT_MAX_ARITY sl@0: // sl@0: // Exposes maximum allowed arity of class templates with recursive_variant sl@0: // arguments. That is, sl@0: // make_recursive_variant< ..., T<[1], recursive_variant_, ... [N]> >. sl@0: // sl@0: #include "boost/mpl/limits/arity.hpp" sl@0: #define BOOST_VARIANT_RECURSIVE_VARIANT_MAX_ARITY \ sl@0: BOOST_MPL_LIMIT_METAFUNCTION_ARITY sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // macro BOOST_VARIANT_ENUM_PARAMS sl@0: // sl@0: // Convenience macro for enumeration of BOOST_VARIANT_LIMIT_TYPES params. sl@0: // sl@0: // Rationale: Cleaner, simpler code for clients of variant library. sl@0: // sl@0: #define BOOST_VARIANT_ENUM_PARAMS( param ) \ sl@0: BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, param) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // macro BOOST_VARIANT_ENUM_SHIFTED_PARAMS sl@0: // sl@0: // Convenience macro for enumeration of BOOST_VARIANT_LIMIT_TYPES-1 params. sl@0: // sl@0: #define BOOST_VARIANT_ENUM_SHIFTED_PARAMS( param ) \ sl@0: BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_VARIANT_LIMIT_TYPES, param) sl@0: sl@0: sl@0: namespace boost { sl@0: sl@0: namespace detail { namespace variant { sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // (detail) class void_ and class template convert_void sl@0: // sl@0: // Provides the mechanism by which void(NN) types are converted to sl@0: // mpl::void_ (and thus can be passed to mpl::list). sl@0: // sl@0: // Rationale: This is particularly needed for the using-declarations sl@0: // workaround (below), but also to avoid associating mpl namespace with sl@0: // variant in argument dependent lookups (which used to happen because of sl@0: // defaulting of template parameters to mpl::void_). sl@0: // sl@0: sl@0: struct void_; sl@0: sl@0: template sl@0: struct convert_void sl@0: { sl@0: typedef T type; sl@0: }; sl@0: sl@0: template <> sl@0: struct convert_void< void_ > sl@0: { sl@0: typedef mpl::na type; sl@0: }; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // (workaround) BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE sl@0: // sl@0: // Needed to work around compilers that don't support using-declaration sl@0: // overloads. (See the variant::initializer workarounds below.) sl@0: // sl@0: sl@0: #if defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE) sl@0: sl@0: // (detail) tags voidNN -- NN defined on [0, BOOST_VARIANT_LIMIT_TYPES) sl@0: // sl@0: // Defines void types that are each unique and specializations of sl@0: // convert_void that yields mpl::na for each voidNN type. sl@0: // sl@0: sl@0: #define BOOST_VARIANT_DETAIL_DEFINE_VOID_N(z,N,_) \ sl@0: struct BOOST_PP_CAT(void,N); \ sl@0: \ sl@0: template <> \ sl@0: struct convert_void< BOOST_PP_CAT(void,N) > \ sl@0: { \ sl@0: typedef mpl::na type; \ sl@0: }; \ sl@0: /**/ sl@0: sl@0: BOOST_PP_REPEAT( sl@0: BOOST_VARIANT_LIMIT_TYPES sl@0: , BOOST_VARIANT_DETAIL_DEFINE_VOID_N sl@0: , _ sl@0: ) sl@0: sl@0: #undef BOOST_VARIANT_DETAIL_DEFINE_VOID_N sl@0: sl@0: #endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround sl@0: sl@0: }} // namespace detail::variant sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // (detail) macro BOOST_VARIANT_AUX_DECLARE_PARAM sl@0: // sl@0: // Template parameter list for variant and recursive_variant declarations. sl@0: // sl@0: sl@0: #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE) sl@0: sl@0: # define BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL(z, N, T) \ sl@0: typename BOOST_PP_CAT(T,N) = detail::variant::void_ \ sl@0: /**/ sl@0: sl@0: #else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE) sl@0: sl@0: # define BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL(z, N, T) \ sl@0: typename BOOST_PP_CAT(T,N) = BOOST_PP_CAT(detail::variant::void,N) \ sl@0: /**/ sl@0: sl@0: #endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround sl@0: sl@0: #define BOOST_VARIANT_AUX_DECLARE_PARAMS \ sl@0: BOOST_PP_ENUM( \ sl@0: BOOST_VARIANT_LIMIT_TYPES \ sl@0: , BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL \ sl@0: , T \ sl@0: ) \ sl@0: /**/ sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // class template variant (concept inspired by Andrei Alexandrescu) sl@0: // sl@0: // Efficient, type-safe bounded discriminated union. sl@0: // sl@0: // Preconditions: sl@0: // - Each type must be unique. sl@0: // - No type may be const-qualified. sl@0: // sl@0: // Proper declaration form: sl@0: // variant (where types is a type-sequence) sl@0: // or sl@0: // variant (where T0 is NOT a type-sequence) sl@0: // sl@0: template < BOOST_VARIANT_AUX_DECLARE_PARAMS > class variant; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // metafunction make_recursive_variant sl@0: // sl@0: // Exposes a boost::variant with recursive_variant_ tags (below) substituted sl@0: // with the variant itself (wrapped as needed with boost::recursive_wrapper). sl@0: // sl@0: template < BOOST_VARIANT_AUX_DECLARE_PARAMS > struct make_recursive_variant; sl@0: sl@0: #undef BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL sl@0: #undef BOOST_VARIANT_AUX_DECLARE_PARAMS sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // type recursive_variant_ sl@0: // sl@0: // Tag type indicates where recursive variant substitution should occur. sl@0: // sl@0: #if !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT) sl@0: struct recursive_variant_; sl@0: #else sl@0: typedef mpl::arg<1> recursive_variant_; sl@0: #endif sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // metafunction make_variant_over sl@0: // sl@0: // Result is a variant w/ types of the specified type sequence. sl@0: // sl@0: template struct make_variant_over; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////// sl@0: // metafunction make_recursive_variant_over sl@0: // sl@0: // Result is a recursive variant w/ types of the specified type sequence. sl@0: // sl@0: template struct make_recursive_variant_over; sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_VARIANT_VARIANT_FWD_HPP