unfused_typed.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*=============================================================================
  2. Copyright (c) 2006-2007 Tobias Schwinger
  3. Use modification and distribution are subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ==============================================================================*/
  7. #if !defined(BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_TYPED_HPP_INCLUDED)
  8. #if !defined(BOOST_PP_IS_ITERATING)
  9. #include <boost/preprocessor/cat.hpp>
  10. #include <boost/preprocessor/iteration/iterate.hpp>
  11. #include <boost/preprocessor/repetition/enum.hpp>
  12. #include <boost/preprocessor/repetition/enum_params.hpp>
  13. #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
  14. #include <boost/config.hpp>
  15. #include <boost/utility/result_of.hpp>
  16. #include <boost/fusion/support/detail/access.hpp>
  17. #include <boost/fusion/sequence/intrinsic/value_at.hpp>
  18. #include <boost/fusion/sequence/intrinsic/size.hpp>
  19. #include <boost/fusion/container/vector/vector.hpp>
  20. #include <boost/fusion/container/vector/convert.hpp>
  21. #include <boost/fusion/functional/adapter/limits.hpp>
  22. #include <boost/fusion/functional/adapter/detail/access.hpp>
  23. #if defined (BOOST_MSVC)
  24. # pragma warning(push)
  25. # pragma warning (disable: 4512) // assignment operator could not be generated.
  26. #endif
  27. namespace boost { namespace fusion
  28. {
  29. template <class Function, class Sequence> class unfused_typed;
  30. //----- ---- --- -- - - - -
  31. namespace detail
  32. {
  33. template <class Derived, class Function,
  34. class Sequence, long Arity>
  35. struct unfused_typed_impl;
  36. }
  37. template <class Function, class Sequence>
  38. class unfused_typed
  39. : public detail::unfused_typed_impl
  40. < unfused_typed<Function,Sequence>, Function, Sequence,
  41. result_of::size<Sequence>::value >
  42. {
  43. Function fnc_transformed;
  44. template <class D, class F, class S, long A>
  45. friend struct detail::unfused_typed_impl;
  46. typedef typename detail::call_param<Function>::type func_const_fwd_t;
  47. public:
  48. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  49. inline explicit unfused_typed(func_const_fwd_t f = Function())
  50. : fnc_transformed(f)
  51. { }
  52. };
  53. #define BOOST_PP_FILENAME_1 <boost/fusion/functional/adapter/unfused_typed.hpp>
  54. #define BOOST_PP_ITERATION_LIMITS (0,BOOST_FUSION_UNFUSED_TYPED_MAX_ARITY)
  55. #include BOOST_PP_ITERATE()
  56. }}
  57. #if defined (BOOST_MSVC)
  58. # pragma warning(pop)
  59. #endif
  60. namespace boost
  61. {
  62. #if !defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_NO_CXX11_DECLTYPE)
  63. template<class F, class Seq>
  64. struct result_of< boost::fusion::unfused_typed<F,Seq> const () >
  65. : boost::fusion::unfused_typed<F,Seq>::template result<
  66. boost::fusion::unfused_typed<F,Seq> const () >
  67. { };
  68. template<class F, class Seq>
  69. struct result_of< boost::fusion::unfused_typed<F,Seq>() >
  70. : boost::fusion::unfused_typed<F,Seq>::template result<
  71. boost::fusion::unfused_typed<F,Seq> () >
  72. { };
  73. #endif
  74. template<class F, class Seq>
  75. struct tr1_result_of< boost::fusion::unfused_typed<F,Seq> const () >
  76. : boost::fusion::unfused_typed<F,Seq>::template result<
  77. boost::fusion::unfused_typed<F,Seq> const () >
  78. { };
  79. template<class F, class Seq>
  80. struct tr1_result_of< boost::fusion::unfused_typed<F,Seq>() >
  81. : boost::fusion::unfused_typed<F,Seq>::template result<
  82. boost::fusion::unfused_typed<F,Seq> () >
  83. { };
  84. }
  85. #define BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_TYPED_HPP_INCLUDED
  86. #else // defined(BOOST_PP_IS_ITERATING)
  87. ///////////////////////////////////////////////////////////////////////////////
  88. //
  89. // Preprocessor vertical repetition code
  90. //
  91. ///////////////////////////////////////////////////////////////////////////////
  92. #define N BOOST_PP_ITERATION()
  93. namespace detail
  94. {
  95. template <class Derived, class Function, class Sequence>
  96. struct unfused_typed_impl<Derived,Function,Sequence,N>
  97. {
  98. typedef typename detail::qf_c<Function>::type function_c;
  99. typedef typename detail::qf<Function>::type function;
  100. typedef typename result_of::as_vector<Sequence>::type arg_vector_t;
  101. public:
  102. #define M(z,i,s) \
  103. typename call_param<typename result_of::value_at_c<s,i>::type>::type a##i
  104. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  105. inline typename boost::result_of<
  106. function_c(arg_vector_t &) >::type
  107. operator()(BOOST_PP_ENUM(N,M,arg_vector_t)) const
  108. {
  109. #if N > 0
  110. arg_vector_t arg(BOOST_PP_ENUM_PARAMS(N,a));
  111. #else
  112. arg_vector_t arg;
  113. #endif
  114. return static_cast<Derived const *>(this)->fnc_transformed(arg);
  115. }
  116. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  117. inline typename boost::result_of<
  118. function(arg_vector_t &) >::type
  119. operator()(BOOST_PP_ENUM(N,M,arg_vector_t))
  120. {
  121. #if N > 0
  122. arg_vector_t arg(BOOST_PP_ENUM_PARAMS(N,a));
  123. #else
  124. arg_vector_t arg;
  125. #endif
  126. return static_cast<Derived *>(this)->fnc_transformed(arg);
  127. }
  128. #undef M
  129. template <typename Sig> struct result { typedef void type; };
  130. template <class Self BOOST_PP_ENUM_TRAILING_PARAMS(N,typename T)>
  131. struct result< Self const (BOOST_PP_ENUM_PARAMS(N,T)) >
  132. : boost::result_of< function_c(arg_vector_t &) >
  133. { };
  134. template <class Self BOOST_PP_ENUM_TRAILING_PARAMS(N,typename T)>
  135. struct result< Self (BOOST_PP_ENUM_PARAMS(N,T)) >
  136. : boost::result_of< function(arg_vector_t &) >
  137. { };
  138. };
  139. } // namespace detail
  140. #undef N
  141. #endif // defined(BOOST_PP_IS_ITERATING)
  142. #endif