substitute.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/substitute.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2003
  7. // Eric Friedman
  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_SUBSTITUTE_HPP
  13. #define BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
  14. #include <boost/mpl/aux_/config/ctps.hpp>
  15. #include <boost/variant/detail/substitute_fwd.hpp>
  16. #include <boost/variant/variant_fwd.hpp>
  17. #include <boost/mpl/aux_/lambda_arity_param.hpp>
  18. #include <boost/mpl/aux_/preprocessor/params.hpp>
  19. #include <boost/mpl/aux_/preprocessor/repeat.hpp>
  20. #include <boost/mpl/int_fwd.hpp>
  21. #include <boost/mpl/limits/arity.hpp>
  22. #include <boost/preprocessor/cat.hpp>
  23. #include <boost/preprocessor/empty.hpp>
  24. #include <boost/preprocessor/arithmetic/inc.hpp>
  25. #include <boost/preprocessor/iterate.hpp>
  26. namespace boost {
  27. namespace detail { namespace variant {
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // (detail) metafunction substitute
  30. //
  31. // Substitutes one type for another in the given type expression.
  32. //
  33. //
  34. // primary template
  35. //
  36. template <
  37. typename T, typename Dest, typename Source
  38. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(
  39. typename Arity /* = ... (see substitute_fwd.hpp) */
  40. )
  41. >
  42. struct substitute
  43. {
  44. typedef T type;
  45. };
  46. //
  47. // tag substitution specializations
  48. //
  49. #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(CV_) \
  50. template <typename Dest, typename Source> \
  51. struct substitute< \
  52. CV_ Source \
  53. , Dest \
  54. , Source \
  55. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) \
  56. > \
  57. { \
  58. typedef CV_ Dest type; \
  59. }; \
  60. /**/
  61. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG( BOOST_PP_EMPTY() )
  62. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(const)
  63. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(volatile)
  64. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(const volatile)
  65. #undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG
  66. //
  67. // pointer specializations
  68. //
  69. #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(CV_) \
  70. template <typename T, typename Dest, typename Source> \
  71. struct substitute< \
  72. T * CV_ \
  73. , Dest \
  74. , Source \
  75. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) \
  76. > \
  77. { \
  78. typedef typename substitute< \
  79. T, Dest, Source \
  80. >::type * CV_ type; \
  81. }; \
  82. /**/
  83. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER( BOOST_PP_EMPTY() )
  84. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(const)
  85. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(volatile)
  86. BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(const volatile)
  87. #undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER
  88. //
  89. // reference specializations
  90. //
  91. template <typename T, typename Dest, typename Source>
  92. struct substitute<
  93. T&
  94. , Dest
  95. , Source
  96. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>)
  97. >
  98. {
  99. typedef typename substitute<
  100. T, Dest, Source
  101. >::type & type;
  102. };
  103. //
  104. // template expression (i.e., F<...>) specializations
  105. //
  106. template <
  107. template <typename...> class F
  108. , typename... Ts
  109. , typename Dest
  110. , typename Source
  111. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity)
  112. >
  113. struct substitute<
  114. F<Ts...>
  115. , Dest
  116. , Source
  117. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
  118. >
  119. {
  120. typedef F<typename substitute<
  121. Ts, Dest, Source
  122. >::type...> type;
  123. };
  124. //
  125. // function specializations
  126. //
  127. template <
  128. typename R
  129. , typename... A
  130. , typename Dest
  131. , typename Source
  132. >
  133. struct substitute<
  134. R (*)(A...)
  135. , Dest
  136. , Source
  137. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>)
  138. >
  139. {
  140. private:
  141. typedef typename substitute< R, Dest, Source >::type r;
  142. public:
  143. typedef r (*type)(typename substitute<
  144. A, Dest, Source
  145. >::type...);
  146. };
  147. }} // namespace detail::variant
  148. } // namespace boost
  149. #endif // BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP