fused.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_HPP_INCLUDED)
  8. #define BOOST_FUSION_FUNCTIONAL_ADAPTER_FUSED_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.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 <typename Function> class fused;
  20. //----- ---- --- -- - - - -
  21. template <typename Function>
  22. class fused
  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(func_const_fwd_t f = Function())
  29. : fnc_transformed(f)
  30. { }
  31. template <class Seq>
  32. inline typename result_of::invoke<func_const_fwd_t,Seq const>::type
  33. operator()(Seq const & s) const
  34. {
  35. return fusion::invoke<func_const_fwd_t>(this->fnc_transformed,s);
  36. }
  37. template <class Seq>
  38. inline typename result_of::invoke<func_fwd_t,Seq const>::type
  39. operator()(Seq const & s)
  40. {
  41. return fusion::invoke<func_fwd_t>(this->fnc_transformed,s);
  42. }
  43. template <class Seq>
  44. inline typename result_of::invoke<func_const_fwd_t,Seq>::type
  45. operator()(Seq & s) const
  46. {
  47. return fusion::invoke<func_const_fwd_t>(this->fnc_transformed,s);
  48. }
  49. template <class Seq>
  50. inline typename result_of::invoke<func_fwd_t,Seq>::type
  51. operator()(Seq & s)
  52. {
  53. return fusion::invoke<func_fwd_t>(this->fnc_transformed,s);
  54. }
  55. template <typename Sig>
  56. struct result;
  57. template <class Self, class Seq>
  58. struct result< Self const (Seq) >
  59. : result_of::invoke<func_const_fwd_t,
  60. typename boost::remove_reference<Seq>::type >
  61. { };
  62. template <class Self, class Seq>
  63. struct result< Self(Seq) >
  64. : result_of::invoke<func_fwd_t,
  65. typename boost::remove_reference<Seq>::type >
  66. { };
  67. };
  68. }}
  69. #if defined (BOOST_MSVC)
  70. # pragma warning(pop)
  71. #endif
  72. #endif