| 1 | //----------------------------------------------------------------------------- |
| 2 | // boost variant/variant_fwd.hpp header file |
| 3 | // See http://www.boost.org for updates, documentation, and revision history. |
| 4 | //----------------------------------------------------------------------------- |
| 5 | // |
| 6 | // Copyright (c) 2003 Eric Friedman, Itay Maman |
| 7 | // Copyright (c) 2013-2024 Antony Polukhin |
| 8 | // |
| 9 | // Distributed under the Boost Software License, Version 1.0. (See |
| 10 | // accompanying file LICENSE_1_0.txt or copy at |
| 11 | // http://www.boost.org/LICENSE_1_0.txt) |
| 12 | |
| 13 | #ifndef BOOST_VARIANT_VARIANT_FWD_HPP |
| 14 | #define BOOST_VARIANT_VARIANT_FWD_HPP |
| 15 | |
| 16 | #include <boost/variant/detail/config.hpp> |
| 17 | |
| 18 | #include <boost/blank_fwd.hpp> |
| 19 | #include <boost/mpl/arg.hpp> |
| 20 | #include <boost/mpl/limits/arity.hpp> |
| 21 | #include <boost/mpl/aux_/na.hpp> |
| 22 | #include <boost/preprocessor/cat.hpp> |
| 23 | #include <boost/preprocessor/enum.hpp> |
| 24 | #include <boost/preprocessor/enum_params.hpp> |
| 25 | #include <boost/preprocessor/enum_shifted_params.hpp> |
| 26 | #include <boost/preprocessor/repeat.hpp> |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | // macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT |
| 30 | // |
| 31 | // Defined if make_recursive_variant cannot be supported as documented. |
| 32 | // |
| 33 | // Note: Currently, MPL lambda facility is used as workaround if defined, and |
| 34 | // so only types declared w/ MPL lambda workarounds will work. |
| 35 | // |
| 36 | |
| 37 | #include <boost/variant/detail/substitute_fwd.hpp> |
| 38 | |
| 39 | #include <boost/preprocessor/seq/size.hpp> |
| 40 | |
| 41 | #define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_class class)( |
| 42 | #define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_typename typename)( |
| 43 | |
| 44 | #define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_class class... |
| 45 | #define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_typename typename... |
| 46 | |
| 47 | #define ARGS_VARIADER_1(x) x ## N... |
| 48 | #define ARGS_VARIADER_2(x) BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_ ## x ## N |
| 49 | |
| 50 | #define BOOST_VARIANT_MAKE_VARIADIC(sequence, x) BOOST_VARIANT_MAKE_VARIADIC_I(BOOST_PP_SEQ_SIZE(sequence), x) |
| 51 | #define BOOST_VARIANT_MAKE_VARIADIC_I(argscount, x) BOOST_VARIANT_MAKE_VARIADIC_II(argscount, x) |
| 52 | #define BOOST_VARIANT_MAKE_VARIADIC_II(argscount, orig) ARGS_VARIADER_ ## argscount(orig) |
| 53 | |
| 54 | /////////////////////////////////////////////////////////////////////////////// |
| 55 | // BOOST_VARIANT_ENUM_PARAMS and BOOST_VARIANT_ENUM_SHIFTED_PARAMS |
| 56 | // |
| 57 | // Convenience macro for enumeration of variant params. |
| 58 | // When variadic templates are available expands: |
| 59 | // BOOST_VARIANT_ENUM_PARAMS(class Something) => class Something0, class... SomethingN |
| 60 | // BOOST_VARIANT_ENUM_PARAMS(typename Something) => typename Something0, typename... SomethingN |
| 61 | // BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN... |
| 62 | // BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN... |
| 63 | // BOOST_VARIANT_ENUM_SHIFTED_PARAMS(class Something) => class... SomethingN |
| 64 | // BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename Something) => typename... SomethingN |
| 65 | // BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN... |
| 66 | // BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN... |
| 67 | // |
| 68 | // Rationale: Cleaner, simpler code for clients of variant library. Minimal |
| 69 | // code modifications to move from C++03 to C++11. |
| 70 | // |
| 71 | |
| 72 | #define BOOST_VARIANT_ENUM_PARAMS(x) \ |
| 73 | x ## 0, \ |
| 74 | BOOST_VARIANT_MAKE_VARIADIC( (BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_ ## x), x) \ |
| 75 | /**/ |
| 76 | |
| 77 | #define BOOST_VARIANT_ENUM_SHIFTED_PARAMS(x) \ |
| 78 | BOOST_VARIANT_MAKE_VARIADIC( (BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_ ## x), x) \ |
| 79 | /**/ |
| 80 | |
| 81 | |
| 82 | namespace boost { |
| 83 | |
| 84 | namespace detail { namespace variant { |
| 85 | |
| 86 | /////////////////////////////////////////////////////////////////////////////// |
| 87 | // (detail) class void_ and class template convert_void |
| 88 | // |
| 89 | // Provides the mechanism by which void(NN) types are converted to |
| 90 | // mpl::void_ (and thus can be passed to mpl::list). |
| 91 | // |
| 92 | // Rationale: This is particularly needed for the using-declarations |
| 93 | // workaround (below), but also to avoid associating mpl namespace with |
| 94 | // variant in argument dependent lookups (which used to happen because of |
| 95 | // defaulting of template parameters to mpl::void_). |
| 96 | // |
| 97 | |
| 98 | struct void_; |
| 99 | |
| 100 | template <typename T> |
| 101 | struct convert_void |
| 102 | { |
| 103 | typedef T type; |
| 104 | }; |
| 105 | |
| 106 | template <> |
| 107 | struct convert_void< void_ > |
| 108 | { |
| 109 | typedef mpl::na type; |
| 110 | }; |
| 111 | |
| 112 | }} // namespace detail::variant |
| 113 | |
| 114 | #define BOOST_VARIANT_AUX_DECLARE_PARAMS BOOST_VARIANT_ENUM_PARAMS(typename T) |
| 115 | |
| 116 | /////////////////////////////////////////////////////////////////////////////// |
| 117 | // class template variant (concept inspired by Andrei Alexandrescu) |
| 118 | // |
| 119 | // Efficient, type-safe bounded discriminated union. |
| 120 | // |
| 121 | // Preconditions: |
| 122 | // - Each type must be unique. |
| 123 | // - No type may be const-qualified. |
| 124 | // |
| 125 | // Proper declaration form: |
| 126 | // variant<types> (where types is a type-sequence) |
| 127 | // or |
| 128 | // variant<T0,T1,...,Tn> (where T0 is NOT a type-sequence) |
| 129 | // |
| 130 | template < BOOST_VARIANT_AUX_DECLARE_PARAMS > class variant; |
| 131 | |
| 132 | /////////////////////////////////////////////////////////////////////////////// |
| 133 | // metafunction make_recursive_variant |
| 134 | // |
| 135 | // Exposes a boost::variant with recursive_variant_ tags (below) substituted |
| 136 | // with the variant itself (wrapped as needed with boost::recursive_wrapper). |
| 137 | // |
| 138 | template < BOOST_VARIANT_AUX_DECLARE_PARAMS > struct make_recursive_variant; |
| 139 | |
| 140 | #undef BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL |
| 141 | #undef BOOST_VARIANT_AUX_DECLARE_PARAMS |
| 142 | |
| 143 | /////////////////////////////////////////////////////////////////////////////// |
| 144 | // type recursive_variant_ |
| 145 | // |
| 146 | // Tag type indicates where recursive variant substitution should occur. |
| 147 | // |
| 148 | #if !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT) |
| 149 | struct recursive_variant_ {}; |
| 150 | #else |
| 151 | typedef mpl::arg<1> recursive_variant_; |
| 152 | #endif |
| 153 | |
| 154 | /////////////////////////////////////////////////////////////////////////////// |
| 155 | // metafunction make_variant_over |
| 156 | // |
| 157 | // Result is a variant w/ types of the specified type sequence. |
| 158 | // |
| 159 | template <typename Types> struct make_variant_over; |
| 160 | |
| 161 | /////////////////////////////////////////////////////////////////////////////// |
| 162 | // metafunction make_recursive_variant_over |
| 163 | // |
| 164 | // Result is a recursive variant w/ types of the specified type sequence. |
| 165 | // |
| 166 | template <typename Types> struct make_recursive_variant_over; |
| 167 | |
| 168 | } // namespace boost |
| 169 | |
| 170 | #endif // BOOST_VARIANT_VARIANT_FWD_HPP |
| 171 | |