variant_fwd.hpp 7.9 KB

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