Boost logo

Boost Users :

From: Rodolfo Lima (rodolfo_at_[hidden])
Date: 2006-11-28 17:49:32


> function<int(const aux &)> f = (&_1->*&aux::a)();

This doesn't work because you are evaluating the functor without
arguments, whereas it requires one.

> function<int(const aux &)> f = bind( &aux::a, _1 );

This would work, but I in my project I have to call operator->* because in
my case aux is a class that models a pointer, but doesn't have a dereference
operator, just operator->* and operator->, those are the only ways to access
the containing pointer. Well, there's also a ptr member function that
returns it, but I'm trying to achieve the most natural way to access the
containing pointer members. By using aux's ptr member, I have to use bind
functions, which is a little unnatural.

> or
>
> function<int(const aux &)> f = &aux::a;

That doesn't make it either because f(a) just would return a delayed call to
&aux::a, not its actual result.

By trying to correct your first example, I've come with:

function<int(const aux &)> f = (&protect(_1)->*&aux::a)();

The rationale is that the first evaluation without parameter would return a
functor that expects an aux object, and would return aux::a return value
(int), but this also fails compiling because
class other_action<member_pointer_action>::apply fails to conclude that
&protect(_1) is actually a pointer, and so it calls
member_pointer_action_helper<false, false>::apply, which is the wrong
choice. IMO the right choice would be member_pointer_action_helper<false,
true> which evaluates the pointer to member function.

Thanks for your help,
Rodolfo Lima.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net