| 1 | /*============================================================================= |
| 2 | Copyright (c) 2016 Kohei Takahashi |
| 3 | |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | ==============================================================================*/ |
| 7 | |
| 8 | #ifndef PHOENIX_BIND_BIND_MEMBER_FUNCTION_HPP |
| 9 | #define PHOENIX_BIND_BIND_MEMBER_FUNCTION_HPP |
| 10 | |
| 11 | #include <boost/phoenix/core/limits.hpp> |
| 12 | |
| 13 | #if defined(BOOST_PHOENIX_NO_VARIADIC_BIND) |
| 14 | # include <boost/phoenix/bind/detail/cpp03/bind_member_function.hpp> |
| 15 | #else |
| 16 | |
| 17 | #include <boost/phoenix/core/expression.hpp> |
| 18 | #include <boost/phoenix/core/reference.hpp> |
| 19 | #include <boost/phoenix/core/detail/function_eval.hpp> |
| 20 | |
| 21 | namespace boost { namespace phoenix |
| 22 | { |
| 23 | namespace detail |
| 24 | { |
| 25 | template <typename RT, typename FP> |
| 26 | struct member_function_ptr |
| 27 | { |
| 28 | typedef RT result_type; |
| 29 | |
| 30 | member_function_ptr(FP fp_) |
| 31 | : fp(fp_) {} |
| 32 | |
| 33 | template <typename Class, typename... A> |
| 34 | result_type operator()(Class& obj, A&... a) const |
| 35 | { |
| 36 | BOOST_PROTO_USE_GET_POINTER(); |
| 37 | |
| 38 | typedef typename proto::detail::class_member_traits<FP>::class_type class_type; |
| 39 | return (BOOST_PROTO_GET_POINTER(class_type, obj)->*fp)(a...); |
| 40 | } |
| 41 | |
| 42 | template <typename Class, typename... A> |
| 43 | result_type operator()(Class* obj, A&... a) const |
| 44 | { |
| 45 | return (obj->*fp)(a...); |
| 46 | } |
| 47 | |
| 48 | bool operator==(member_function_ptr const& rhs) const |
| 49 | { |
| 50 | return fp == rhs.fp; |
| 51 | } |
| 52 | |
| 53 | template <int M, typename RhsRT, typename RhsFP> |
| 54 | bool operator==(member_function_ptr<RhsRT, RhsFP> const& /*rhs*/) const |
| 55 | { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | FP fp; |
| 60 | }; |
| 61 | } // namespace boost::phoenix::detail |
| 62 | |
| 63 | template <typename RT, typename ClassT, typename... T, typename ClassA, typename... A> |
| 64 | inline |
| 65 | typename detail::expression::function_eval< |
| 66 | detail::member_function_ptr<RT, RT(ClassT::*)(T...)> |
| 67 | , ClassA |
| 68 | , A... |
| 69 | >::type const |
| 70 | bind(RT (ClassT::*f)(T...), ClassA const & obj, A const&... a) |
| 71 | { |
| 72 | typedef detail::member_function_ptr<RT, RT (ClassT::*)(T...)> fp_type; |
| 73 | return detail::expression::function_eval<fp_type, ClassA, A...>::make(fp_type(f), obj, a...); |
| 74 | } |
| 75 | |
| 76 | template <typename RT, typename ClassT, typename... T, typename ClassA, typename... A> |
| 77 | inline |
| 78 | typename detail::expression::function_eval< |
| 79 | detail::member_function_ptr<RT, RT (ClassT::*)(T...) const> |
| 80 | , ClassA |
| 81 | , A... |
| 82 | >::type const |
| 83 | bind(RT (ClassT::*f)(T...) const, ClassA const & obj, A const&... a) |
| 84 | { |
| 85 | typedef detail::member_function_ptr<RT, RT(ClassT::*)(T...) const> fp_type; |
| 86 | return detail::expression::function_eval<fp_type, ClassA, A...>::make(fp_type(f), obj, a...); |
| 87 | } |
| 88 | |
| 89 | template <typename RT, typename ClassT, typename... T, typename... A> |
| 90 | inline |
| 91 | typename detail::expression::function_eval< |
| 92 | detail::member_function_ptr<RT, RT(ClassT::*)(T...)> |
| 93 | , ClassT |
| 94 | , A... |
| 95 | >::type const |
| 96 | bind(RT (ClassT::*f)(T...), ClassT & obj, A const&... a) |
| 97 | { |
| 98 | typedef detail::member_function_ptr<RT, RT(ClassT::*)(T...)> fp_type; |
| 99 | return detail::expression::function_eval<fp_type, ClassT, A...>::make(fp_type(f), obj, a...); |
| 100 | } |
| 101 | |
| 102 | template <typename RT, typename ClassT, typename... T, typename... A> |
| 103 | inline |
| 104 | typename detail::expression::function_eval< |
| 105 | detail::member_function_ptr<RT, RT(ClassT::*)(T...) const> |
| 106 | , ClassT |
| 107 | , A... |
| 108 | >::type const |
| 109 | bind(RT (ClassT::*f)(T...) const, ClassT const& obj, A const&... a) |
| 110 | { |
| 111 | typedef detail::member_function_ptr<RT, RT(ClassT::*)(T...) const> fp_type; |
| 112 | return detail::expression::function_eval<fp_type, ClassT, A...>::make(fp_type(f), obj, a...); |
| 113 | } |
| 114 | }} // namespace boost::phoenix |
| 115 | |
| 116 | #endif |
| 117 | #endif |
| 118 | |