/Src/Dependencies/Boost/boost/variant/variant_fwd.hpp

http://hadesmem.googlecode.com/ · C++ Header · 253 lines · 91 code · 42 blank · 120 comment · 3 complexity · 94e2f8fe3e8d53a8a04f2334278919af MD5 · raw file

  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
  7. // Eric Friedman, Itay Maman
  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_LIMIT_TYPES
  26. //
  27. // Implementation-defined preprocessor symbol describing the actual
  28. // length of variant's pseudo-variadic template parameter list.
  29. //
  30. #include "boost/mpl/limits/list.hpp"
  31. #define BOOST_VARIANT_LIMIT_TYPES \
  32. BOOST_MPL_LIMIT_LIST_SIZE
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // macro BOOST_VARIANT_NO_REFERENCE_SUPPORT
  35. //
  36. // Defined if variant does not support references as bounded types.
  37. //
  38. #if defined(BOOST_VARIANT_AUX_BROKEN_CONSTRUCTOR_TEMPLATE_ORDERING) \
  39. && !defined(BOOST_VARIANT_AUX_HAS_CONSTRUCTOR_TEMPLATE_ORDERING_SFINAE_WKND) \
  40. && !defined(BOOST_VARIANT_NO_REFERENCE_SUPPORT)
  41. # define BOOST_VARIANT_NO_REFERENCE_SUPPORT
  42. #endif
  43. ///////////////////////////////////////////////////////////////////////////////
  44. // macro BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT
  45. //
  46. // Defined if variant does not support make_variant_over (see below).
  47. //
  48. #if defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  49. # define BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT
  50. #endif
  51. ///////////////////////////////////////////////////////////////////////////////
  52. // macro BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT
  53. //
  54. // Defined if make_recursive_variant cannot be supported as documented.
  55. //
  56. // Note: Currently, MPL lambda facility is used as workaround if defined, and
  57. // so only types declared w/ MPL lambda workarounds will work.
  58. //
  59. #include "boost/variant/detail/substitute_fwd.hpp"
  60. #if defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE) \
  61. && !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT)
  62. # define BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT
  63. #endif
  64. ///////////////////////////////////////////////////////////////////////////////
  65. // macro BOOST_VARIANT_RECURSIVE_VARIANT_MAX_ARITY
  66. //
  67. // Exposes maximum allowed arity of class templates with recursive_variant
  68. // arguments. That is,
  69. // make_recursive_variant< ..., T<[1], recursive_variant_, ... [N]> >.
  70. //
  71. #include "boost/mpl/limits/arity.hpp"
  72. #define BOOST_VARIANT_RECURSIVE_VARIANT_MAX_ARITY \
  73. BOOST_MPL_LIMIT_METAFUNCTION_ARITY
  74. ///////////////////////////////////////////////////////////////////////////////
  75. // macro BOOST_VARIANT_ENUM_PARAMS
  76. //
  77. // Convenience macro for enumeration of BOOST_VARIANT_LIMIT_TYPES params.
  78. //
  79. // Rationale: Cleaner, simpler code for clients of variant library.
  80. //
  81. #define BOOST_VARIANT_ENUM_PARAMS( param ) \
  82. BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, param)
  83. ///////////////////////////////////////////////////////////////////////////////
  84. // macro BOOST_VARIANT_ENUM_SHIFTED_PARAMS
  85. //
  86. // Convenience macro for enumeration of BOOST_VARIANT_LIMIT_TYPES-1 params.
  87. //
  88. #define BOOST_VARIANT_ENUM_SHIFTED_PARAMS( param ) \
  89. BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_VARIANT_LIMIT_TYPES, param)
  90. namespace boost {
  91. namespace detail { namespace variant {
  92. ///////////////////////////////////////////////////////////////////////////////
  93. // (detail) class void_ and class template convert_void
  94. //
  95. // Provides the mechanism by which void(NN) types are converted to
  96. // mpl::void_ (and thus can be passed to mpl::list).
  97. //
  98. // Rationale: This is particularly needed for the using-declarations
  99. // workaround (below), but also to avoid associating mpl namespace with
  100. // variant in argument dependent lookups (which used to happen because of
  101. // defaulting of template parameters to mpl::void_).
  102. //
  103. struct void_;
  104. template <typename T>
  105. struct convert_void
  106. {
  107. typedef T type;
  108. };
  109. template <>
  110. struct convert_void< void_ >
  111. {
  112. typedef mpl::na type;
  113. };
  114. ///////////////////////////////////////////////////////////////////////////////
  115. // (workaround) BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE
  116. //
  117. // Needed to work around compilers that don't support using-declaration
  118. // overloads. (See the variant::initializer workarounds below.)
  119. //
  120. #if defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  121. // (detail) tags voidNN -- NN defined on [0, BOOST_VARIANT_LIMIT_TYPES)
  122. //
  123. // Defines void types that are each unique and specializations of
  124. // convert_void that yields mpl::na for each voidNN type.
  125. //
  126. #define BOOST_VARIANT_DETAIL_DEFINE_VOID_N(z,N,_) \
  127. struct BOOST_PP_CAT(void,N); \
  128. \
  129. template <> \
  130. struct convert_void< BOOST_PP_CAT(void,N) > \
  131. { \
  132. typedef mpl::na type; \
  133. }; \
  134. /**/
  135. BOOST_PP_REPEAT(
  136. BOOST_VARIANT_LIMIT_TYPES
  137. , BOOST_VARIANT_DETAIL_DEFINE_VOID_N
  138. , _
  139. )
  140. #undef BOOST_VARIANT_DETAIL_DEFINE_VOID_N
  141. #endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
  142. }} // namespace detail::variant
  143. ///////////////////////////////////////////////////////////////////////////////
  144. // (detail) macro BOOST_VARIANT_AUX_DECLARE_PARAM
  145. //
  146. // Template parameter list for variant and recursive_variant declarations.
  147. //
  148. #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  149. # define BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL(z, N, T) \
  150. typename BOOST_PP_CAT(T,N) = detail::variant::void_ \
  151. /**/
  152. #else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  153. # define BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL(z, N, T) \
  154. typename BOOST_PP_CAT(T,N) = BOOST_PP_CAT(detail::variant::void,N) \
  155. /**/
  156. #endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
  157. #define BOOST_VARIANT_AUX_DECLARE_PARAMS \
  158. BOOST_PP_ENUM( \
  159. BOOST_VARIANT_LIMIT_TYPES \
  160. , BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL \
  161. , T \
  162. ) \
  163. /**/
  164. ///////////////////////////////////////////////////////////////////////////////
  165. // class template variant (concept inspired by Andrei Alexandrescu)
  166. //
  167. // Efficient, type-safe bounded discriminated union.
  168. //
  169. // Preconditions:
  170. // - Each type must be unique.
  171. // - No type may be const-qualified.
  172. //
  173. // Proper declaration form:
  174. // variant<types> (where types is a type-sequence)
  175. // or
  176. // variant<T0,T1,...,Tn> (where T0 is NOT a type-sequence)
  177. //
  178. template < BOOST_VARIANT_AUX_DECLARE_PARAMS > class variant;
  179. ///////////////////////////////////////////////////////////////////////////////
  180. // metafunction make_recursive_variant
  181. //
  182. // Exposes a boost::variant with recursive_variant_ tags (below) substituted
  183. // with the variant itself (wrapped as needed with boost::recursive_wrapper).
  184. //
  185. template < BOOST_VARIANT_AUX_DECLARE_PARAMS > struct make_recursive_variant;
  186. #undef BOOST_VARIANT_AUX_DECLARE_PARAMS_IMPL
  187. #undef BOOST_VARIANT_AUX_DECLARE_PARAMS
  188. ///////////////////////////////////////////////////////////////////////////////
  189. // type recursive_variant_
  190. //
  191. // Tag type indicates where recursive variant substitution should occur.
  192. //
  193. #if !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT)
  194. struct recursive_variant_ {};
  195. #else
  196. typedef mpl::arg<1> recursive_variant_;
  197. #endif
  198. ///////////////////////////////////////////////////////////////////////////////
  199. // metafunction make_variant_over
  200. //
  201. // Result is a variant w/ types of the specified type sequence.
  202. //
  203. template <typename Types> struct make_variant_over;
  204. ///////////////////////////////////////////////////////////////////////////////
  205. // metafunction make_recursive_variant_over
  206. //
  207. // Result is a recursive variant w/ types of the specified type sequence.
  208. //
  209. template <typename Types> struct make_recursive_variant_over;
  210. } // namespace boost
  211. #endif // BOOST_VARIANT_VARIANT_FWD_HPP