bind_function.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #ifndef PHOENIX_BIND_BIND_FUNCTION_HPP
  7. #define PHOENIX_BIND_BIND_FUNCTION_HPP
  8. #include <boost/spirit/home/phoenix/core/compose.hpp>
  9. #include <boost/spirit/home/phoenix/core/detail/function_eval.hpp>
  10. #include <boost/spirit/home/phoenix/bind/detail/function_ptr.hpp>
  11. namespace boost { namespace phoenix
  12. {
  13. template <typename RT>
  14. inline actor<
  15. typename as_composite<
  16. detail::function_eval<0>
  17. , detail::function_ptr<0, RT, RT(*)()>
  18. >::type>
  19. bind(RT(*f)())
  20. {
  21. typedef detail::function_ptr<0, RT, RT(*)()> fp_type;
  22. return compose<detail::function_eval<0> >(fp_type(f));
  23. }
  24. template <typename RT, typename T0, typename A0>
  25. inline actor<
  26. typename as_composite<
  27. detail::function_eval<1>
  28. , detail::function_ptr<1, RT, RT(*)(T0)>
  29. , A0
  30. >::type>
  31. bind(RT(*f)(T0), A0 const& _0)
  32. {
  33. typedef detail::function_ptr<1, RT, RT(*)(T0)> fp_type;
  34. return compose<detail::function_eval<1> >(fp_type(f), _0);
  35. }
  36. template <typename RT, typename T0, typename T1, typename A0, typename A1>
  37. inline actor<
  38. typename as_composite<
  39. detail::function_eval<2>
  40. , detail::function_ptr<2, RT, RT(*)(T0, T1)>
  41. , A0, A1
  42. >::type>
  43. bind(RT(*f)(T0, T1), A0 const& _0, A1 const& _1)
  44. {
  45. typedef detail::function_ptr<2, RT, RT(*)(T0, T1)> fp_type;
  46. return compose<detail::function_eval<2> >(fp_type(f), _0, _1);
  47. }
  48. // Bring in the rest of the function binders
  49. #include <boost/spirit/home/phoenix/bind/detail/bind_function.hpp>
  50. }}
  51. #endif