bind_function.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*=============================================================================
  2. Copyright (c) 2016 Kohei Takahashi
  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/phoenix/core/limits.hpp>
  9. #if defined(BOOST_PHOENIX_NO_VARIADIC_BIND)
  10. # include <boost/phoenix/bind/detail/cpp03/bind_function.hpp>
  11. #else
  12. #include <boost/phoenix/core/expression.hpp>
  13. #include <boost/phoenix/core/detail/function_eval.hpp>
  14. namespace boost { namespace phoenix
  15. {
  16. namespace detail
  17. {
  18. template <typename RT, typename FP>
  19. struct function_ptr
  20. {
  21. typedef RT result_type;
  22. function_ptr(FP fp_)
  23. : fp(fp_) {}
  24. template <typename... A>
  25. result_type operator()(A&... a) const
  26. {
  27. return fp(a...);
  28. }
  29. bool operator==(function_ptr const& rhs) const
  30. {
  31. return fp == rhs.fp;
  32. }
  33. template <typename RhsRT, typename RhsFP>
  34. bool operator==(function_ptr<RhsRT, RhsFP> const& /*rhs*/) const
  35. {
  36. return false;
  37. }
  38. FP fp;
  39. };
  40. } // namespace boost::phoenix::detail
  41. template <typename RT, typename... T, typename... A>
  42. inline typename detail::expression::function_eval<
  43. detail::function_ptr<RT, RT (*)(T...)>
  44. , A...
  45. >::type const
  46. bind(RT (*f)(T...), A const&... a)
  47. {
  48. typedef detail::function_ptr<RT, RT (*)(T...)> fp_type;
  49. return detail::expression::function_eval<fp_type, A...>::make(fp_type(f), a...);
  50. }
  51. }} // namespace boost::phoenix
  52. #endif
  53. #endif