unfused.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_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_params.hpp>
  12. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  13. #include <boost/preprocessor/facilities/intercept.hpp>
  14. #include <boost/utility/result_of.hpp>
  15. #include <boost/config.hpp>
  16. #include <boost/fusion/container/vector/vector.hpp>
  17. #include <boost/fusion/functional/adapter/limits.hpp>
  18. #include <boost/fusion/functional/adapter/detail/access.hpp>
  19. #if defined (BOOST_MSVC)
  20. # pragma warning(push)
  21. # pragma warning (disable: 4512) // assignment operator could not be generated.
  22. #endif
  23. namespace boost { namespace fusion
  24. {
  25. template <class Function, bool AllowNullary = true>
  26. class unfused;
  27. //----- ---- --- -- - - - -
  28. template <class Function>
  29. class unfused<Function,true>
  30. : public unfused<Function,false>
  31. {
  32. typedef typename detail::qf_c<Function>::type function_c;
  33. typedef typename detail::qf<Function>::type function;
  34. typedef typename detail::call_param<Function>::type func_const_fwd_t;
  35. public:
  36. using unfused<Function,false>::operator();
  37. inline explicit unfused(func_const_fwd_t f = function())
  38. : unfused<Function,false>(f)
  39. { }
  40. typedef typename boost::result_of<
  41. function_c(fusion::vector0<> &) >::type call_const_0_result;
  42. inline call_const_0_result operator()() const
  43. {
  44. fusion::vector0<> arg;
  45. return this->fnc_transformed(arg);
  46. }
  47. typedef typename boost::result_of<
  48. function(fusion::vector0<> &) >::type call_0_result;
  49. inline call_0_result operator()()
  50. {
  51. fusion::vector0<> arg;
  52. return this->fnc_transformed(arg);
  53. }
  54. };
  55. template <class Function> class unfused<Function,false>
  56. {
  57. protected:
  58. Function fnc_transformed;
  59. typedef typename detail::qf_c<Function>::type function_c;
  60. typedef typename detail::qf<Function>::type function;
  61. typedef typename detail::call_param<Function>::type func_const_fwd_t;
  62. public:
  63. inline explicit unfused(func_const_fwd_t f = function())
  64. : fnc_transformed(f)
  65. { }
  66. template <typename Sig>
  67. struct result;
  68. #define BOOST_PP_FILENAME_1 \
  69. <boost/fusion/functional/adapter/unfused.hpp>
  70. #define BOOST_PP_ITERATION_LIMITS \
  71. (1,BOOST_FUSION_UNFUSED_MAX_ARITY)
  72. #include BOOST_PP_ITERATE()
  73. };
  74. }}
  75. #if defined (BOOST_MSVC)
  76. # pragma warning(pop)
  77. #endif
  78. namespace boost
  79. {
  80. #if !defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_NO_CXX11_DECLTYPE)
  81. template<class F>
  82. struct result_of< boost::fusion::unfused<F> const () >
  83. {
  84. typedef typename boost::fusion::unfused<F>::call_const_0_result type;
  85. };
  86. template<class F>
  87. struct result_of< boost::fusion::unfused<F>() >
  88. {
  89. typedef typename boost::fusion::unfused<F>::call_0_result type;
  90. };
  91. #endif
  92. template<class F>
  93. struct tr1_result_of< boost::fusion::unfused<F> const () >
  94. {
  95. typedef typename boost::fusion::unfused<F>::call_const_0_result type;
  96. };
  97. template<class F>
  98. struct tr1_result_of< boost::fusion::unfused<F>() >
  99. {
  100. typedef typename boost::fusion::unfused<F>::call_0_result type;
  101. };
  102. }
  103. #define BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_HPP_INCLUDED
  104. #else // defined(BOOST_PP_IS_ITERATING)
  105. ////////////////////////////////////////////////////////////////////////////////
  106. //
  107. // Preprocessor vertical repetition code
  108. //
  109. ////////////////////////////////////////////////////////////////////////////////
  110. #define N BOOST_PP_ITERATION()
  111. template <class Self, BOOST_PP_ENUM_PARAMS(N,typename T)>
  112. struct result< Self const (BOOST_PP_ENUM_PARAMS(N,T)) >
  113. : boost::result_of< function_c(
  114. BOOST_PP_CAT(fusion::vector,N)< BOOST_PP_ENUM_BINARY_PARAMS(N,
  115. typename detail::mref<T,>::type BOOST_PP_INTERCEPT) > & )>
  116. { };
  117. template <class Self, BOOST_PP_ENUM_PARAMS(N,typename T)>
  118. struct result< Self(BOOST_PP_ENUM_PARAMS(N,T)) >
  119. : boost::result_of< function(
  120. BOOST_PP_CAT(fusion::vector,N)< BOOST_PP_ENUM_BINARY_PARAMS(N,
  121. typename detail::mref<T,>::type BOOST_PP_INTERCEPT) > & )>
  122. { };
  123. template <BOOST_PP_ENUM_PARAMS(N,typename T)>
  124. inline typename boost::result_of<function_c(BOOST_PP_CAT(fusion::vector,N)
  125. <BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)> & )>::type
  126. operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
  127. {
  128. BOOST_PP_CAT(fusion::vector,N)<
  129. BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT) >
  130. arg(BOOST_PP_ENUM_PARAMS(N,a));
  131. return this->fnc_transformed(arg);
  132. }
  133. template <BOOST_PP_ENUM_PARAMS(N,typename T)>
  134. inline typename boost::result_of<function(BOOST_PP_CAT(fusion::vector,N)
  135. <BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)> & )>::type
  136. operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a))
  137. {
  138. BOOST_PP_CAT(fusion::vector,N)<
  139. BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT) >
  140. arg(BOOST_PP_ENUM_PARAMS(N,a));
  141. return this->fnc_transformed(arg);
  142. }
  143. #undef N
  144. #endif // defined(BOOST_PP_IS_ITERATING)
  145. #endif