fused_function_object.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_FUSED_FUNCTION_OBJECT_HPP_INCLUDED)
  8. #define BOOST_FUSION_FUNCTIONAL_ADAPTER_FUSED_FUNCTION_OBJECT_HPP_INCLUDED
  9. #include <boost/type_traits/add_reference.hpp>
  10. #include <boost/config.hpp>
  11. #include <boost/fusion/functional/adapter/detail/access.hpp>
  12. #include <boost/fusion/functional/invocation/invoke_function_object.hpp>
  13. #if defined (BOOST_MSVC)
  14. # pragma warning(push)
  15. # pragma warning (disable: 4512) // assignment operator could not be generated.
  16. #endif
  17. namespace boost { namespace fusion
  18. {
  19. template <class Function> class fused_function_object;
  20. //----- ---- --- -- - - - -
  21. template <class Function>
  22. class fused_function_object
  23. {
  24. Function fnc_transformed;
  25. typedef typename detail::qf_c<Function>::type & func_const_fwd_t;
  26. typedef typename detail::qf<Function>::type & func_fwd_t;
  27. public:
  28. inline explicit fused_function_object(func_const_fwd_t f = Function())
  29. : fnc_transformed(f)
  30. { }
  31. template <class Seq>
  32. inline typename result_of::invoke_function_object<func_const_fwd_t,
  33. Seq const>::type operator()(Seq const & s) const
  34. {
  35. return fusion::invoke_function_object<
  36. func_const_fwd_t >(this->fnc_transformed,s);
  37. }
  38. template <class Seq>
  39. inline typename result_of::invoke_function_object<func_fwd_t,
  40. Seq const>::type
  41. operator()(Seq const & s)
  42. {
  43. return fusion::invoke_function_object<
  44. func_fwd_t >(this->fnc_transformed,s);
  45. }
  46. template <class Seq>
  47. inline typename result_of::invoke_function_object<func_const_fwd_t,
  48. Seq>::type
  49. operator()(Seq & s) const
  50. {
  51. return fusion::invoke_function_object<
  52. func_const_fwd_t >(this->fnc_transformed,s);
  53. }
  54. template <class Seq>
  55. inline typename result_of::invoke_function_object<func_fwd_t,Seq>::type
  56. operator()(Seq & s)
  57. {
  58. return fusion::invoke_function_object<
  59. func_fwd_t >(this->fnc_transformed,s);
  60. }
  61. template <typename Sig>
  62. struct result;
  63. template <class Self, class Seq>
  64. struct result< Self const (Seq) >
  65. : result_of::invoke_function_object<func_const_fwd_t,
  66. typename boost::remove_reference<Seq>::type >
  67. { };
  68. template <class Self, class Seq>
  69. struct result< Self(Seq) >
  70. : result_of::invoke_function_object<func_fwd_t,
  71. typename boost::remove_reference<Seq>::type >
  72. { };
  73. };
  74. }}
  75. #if defined (BOOST_MSVC)
  76. # pragma warning(pop)
  77. #endif
  78. #endif