/Src/Dependencies/Boost/boost/variant/detail/initializer.hpp

http://hadesmem.googlecode.com/ · C++ Header · 265 lines · 160 code · 56 blank · 49 comment · 5 complexity · 7db2fb4752c543b3d9b35840367c9f68 MD5 · raw file

  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/initializer.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2002-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_DETAIL_INITIALIZER_HPP
  13. #define BOOST_VARIANT_DETAIL_INITIALIZER_HPP
  14. #include <new> // for placement new
  15. #include "boost/config.hpp"
  16. #include "boost/call_traits.hpp"
  17. #include "boost/detail/reference_content.hpp"
  18. #include "boost/variant/recursive_wrapper_fwd.hpp"
  19. #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  20. # include "boost/mpl/aux_/value_wknd.hpp"
  21. # include "boost/mpl/int.hpp"
  22. # include "boost/mpl/iter_fold.hpp"
  23. # include "boost/mpl/next.hpp"
  24. # include "boost/mpl/deref.hpp"
  25. # include "boost/mpl/pair.hpp"
  26. # include "boost/mpl/protect.hpp"
  27. #else
  28. # include "boost/variant/variant_fwd.hpp"
  29. # include "boost/preprocessor/cat.hpp"
  30. # include "boost/preprocessor/enum.hpp"
  31. # include "boost/preprocessor/repeat.hpp"
  32. #endif
  33. namespace boost {
  34. namespace detail { namespace variant {
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // (detail) support to simulate standard overload resolution rules
  37. //
  38. // The below initializers allows variant to follow standard overload
  39. // resolution rules over the specified set of bounded types.
  40. //
  41. // On compilers where using declarations in class templates can correctly
  42. // avoid name hiding, use an optimal solution based on the variant's typelist.
  43. //
  44. // Otherwise, use a preprocessor workaround based on knowledge of the fixed
  45. // size of the variant's psuedo-variadic template parameter list.
  46. //
  47. #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  48. // (detail) quoted metafunction make_initializer_node
  49. //
  50. // Exposes a pair whose first type is a node in the initializer hierarchy.
  51. //
  52. struct make_initializer_node
  53. {
  54. template <typename BaseIndexPair, typename Iterator>
  55. struct apply
  56. {
  57. private: // helpers, for metafunction result (below)
  58. typedef typename BaseIndexPair::first
  59. base;
  60. typedef typename BaseIndexPair::second
  61. index;
  62. class initializer_node
  63. : public base
  64. {
  65. private: // helpers, for static functions (below)
  66. typedef typename mpl::deref<Iterator>::type
  67. recursive_enabled_T;
  68. typedef typename unwrap_recursive<recursive_enabled_T>::type
  69. public_T;
  70. typedef typename call_traits<public_T>::param_type
  71. param_T;
  72. public: // static functions
  73. using base::initialize;
  74. static int initialize(void* dest, param_T operand)
  75. {
  76. typedef typename boost::detail::make_reference_content<
  77. recursive_enabled_T
  78. >::type internal_T;
  79. new(dest) internal_T(operand);
  80. return BOOST_MPL_AUX_VALUE_WKND(index)::value; // which
  81. }
  82. };
  83. friend class initializer_node;
  84. public: // metafunction result
  85. typedef mpl::pair<
  86. initializer_node
  87. , typename mpl::next< index >::type
  88. > type;
  89. };
  90. };
  91. // (detail) class initializer_root
  92. //
  93. // Every level of the initializer hierarchy must expose the name
  94. // "initialize," so initializer_root provides a dummy function:
  95. //
  96. class initializer_root
  97. {
  98. public: // static functions
  99. static void initialize();
  100. };
  101. #else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  102. # if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  103. #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
  104. BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
  105. /**/
  106. #define BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
  107. typedef typename unwrap_recursive< \
  108. BOOST_PP_CAT(recursive_enabled_T,N) \
  109. >::type BOOST_PP_CAT(public_T,N); \
  110. typedef typename call_traits< \
  111. BOOST_PP_CAT(public_T,N) \
  112. >::param_type BOOST_PP_CAT(param_T,N); \
  113. /**/
  114. # else // MSVC7 and below
  115. #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS \
  116. BOOST_VARIANT_ENUM_PARAMS(typename recursive_enabled_T) \
  117. , BOOST_VARIANT_ENUM_PARAMS(typename param_T) \
  118. /**/
  119. #define BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
  120. /**/
  121. # endif // MSVC7 and below workaround
  122. template < BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_PARAMS >
  123. struct preprocessor_list_initializer
  124. {
  125. public: // static functions
  126. #define BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION(z,N,_) \
  127. BOOST_VARIANT_AUX_PP_INITIALIZER_DEFINE_PARAM_T(N) \
  128. static int initialize( \
  129. void* dest \
  130. , BOOST_PP_CAT(param_T,N) operand \
  131. ) \
  132. { \
  133. typedef typename boost::detail::make_reference_content< \
  134. BOOST_PP_CAT(recursive_enabled_T,N) \
  135. >::type internal_T; \
  136. \
  137. new(dest) internal_T(operand); \
  138. return (N); /*which*/ \
  139. } \
  140. /**/
  141. BOOST_PP_REPEAT(
  142. BOOST_VARIANT_LIMIT_TYPES
  143. , BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
  144. , _
  145. )
  146. #undef BOOST_VARIANT_AUX_PP_INITIALIZE_FUNCTION
  147. };
  148. # if defined(BOOST_MPL_CFG_MSVC_60_ETI_BUG)
  149. #if !defined(BOOST_VARIANT_AUX_ECHO)
  150. # define BOOST_VARIANT_AUX_ECHO(z,N,token) token
  151. #endif
  152. template <>
  153. struct preprocessor_list_initializer<
  154. BOOST_PP_ENUM(BOOST_VARIANT_LIMIT_TYPES, BOOST_VARIANT_AUX_ECHO, int)
  155. , BOOST_PP_ENUM(BOOST_VARIANT_LIMIT_TYPES, BOOST_VARIANT_AUX_ECHO, const int)
  156. >
  157. {
  158. };
  159. # endif // BOOST_MPL_CFG_MSVC_60_ETI_BUG workaround
  160. #endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
  161. }} // namespace detail::variant
  162. } // namespace boost
  163. ///////////////////////////////////////////////////////////////////////////////
  164. // macro BOOST_VARIANT_AUX_INITIALIZER_T
  165. //
  166. // Given both the variant's typelist and a basename for forming the list of
  167. // bounded types (i.e., T becomes T1, T2, etc.), exposes the initializer
  168. // most appropriate to the current compiler.
  169. //
  170. #if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  171. #define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
  172. ::boost::mpl::iter_fold< \
  173. mpl_seq \
  174. , ::boost::mpl::pair< \
  175. ::boost::detail::variant::initializer_root \
  176. , ::boost::mpl::int_<0> \
  177. > \
  178. , ::boost::mpl::protect< \
  179. ::boost::detail::variant::make_initializer_node \
  180. > \
  181. >::type::first \
  182. /**/
  183. #else // defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
  184. # if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  185. #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
  186. BOOST_VARIANT_ENUM_PARAMS(typename_base) \
  187. /**/
  188. # else // MSVC7 and below
  189. #define BOOST_VARIANT_AUX_PP_INITIALIZER_ENUM_PARAM_TYPE(z,N,T) \
  190. ::boost::call_traits< \
  191. ::boost::unwrap_recursive<BOOST_PP_CAT(T,N)>::type \
  192. >::param_type \
  193. /**/
  194. #define BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
  195. BOOST_VARIANT_ENUM_PARAMS(typename_base) \
  196. , BOOST_PP_ENUM( \
  197. BOOST_VARIANT_LIMIT_TYPES \
  198. , BOOST_VARIANT_AUX_PP_INITIALIZER_ENUM_PARAM_TYPE \
  199. , typename_base \
  200. ) \
  201. /**/
  202. # endif // MSVC7 workaround
  203. #define BOOST_VARIANT_AUX_INITIALIZER_T( mpl_seq, typename_base ) \
  204. ::boost::detail::variant::preprocessor_list_initializer< \
  205. BOOST_VARIANT_AUX_PP_INITIALIZER_TEMPLATE_ARGS(typename_base) \
  206. > \
  207. /**/
  208. #endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
  209. #endif // BOOST_VARIANT_DETAIL_INITIALIZER_HPP