On 01/31/2012 02:52 PM, Michael Wild wrote:

You might be able to address that by having two make_helper functions,
using enable_if/disable_if to select one when the return type is const
and the other when it isn't.  The one invoked for const returns would
just call make_function directly to make a getter, while the non-const
one would be like make_set_helper above.


Jim

Sorry, I think you'll have to expand a bit on that. Do you mean that I
can use enable_if/disable_if to select between the two implementations?


I think so; again, I haven't tested.

Here's the idea:

template <typename F>
typename boost::enable_if<
    boost::is_const<
        typename boost::function_types::result_type<F>::type
    >,
    bp::object
>::type
make_helper(F f) {
    // deduce A and T ...
    return bp::make_function(
        (A const & (T::*() const))f,
        bp::return_value_policy<copy_const_reference>()
    );
}

template <typename F>
typename boost::disable_if<
    boost::is_const<
        typename boost::function_types::result_type<F>::type
    >,
    bp::object
>::type
make_helper(F f) {
    // deduce A and T ...
    return bp::make_function(&set_helper<A,T,f>);
}

Hope that works!

Jim
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to