|
Boost : |
From: Rodolfo Lima (rodolfo_at_[hidden])
Date: 2006-11-28 20:44:41
Hi, I'm trying to use boost::function with a functor defined with
boost::lambda that uses a dereference to a pointer to member function,
without success. Here goes what I've done up to now:
struct aux
{
aux() : b(1) {}
int a(int x) const { return x+5; }
int b;
};
int main()
{
aux a;
int x = 4;
// This compiles and executes as expected, we're dealing with a pointer
to an attribute.
boost::function<int(const aux &)> fa = &_1->*&aux::b;
int ia = fa(a);
cout << ia << endl;
// This should compile, but doesn't
boost::function<int(const aux &)> fm1 = (&protect(_1)->*&aux::a)(x);
int im1 = fm1(a);
cout << im1 << endl;
// This works, but it's not what we want
// To mimic c++0x auto type (with help of g++'s typeof)
#define auto(var, def) typeof(def) var = def
auto(fm2, &_1->*&aux::a);
int im2 = fm2(a)(x);
cout << im2 << endl;
return 0;
}
By using protect I want to postpone the evaluation of _1 so that it'll occur
after the evaluation of aux::a arguments, but it doesn't work. Does anyone
can help me?
Thanks,
Rodolfo Lima.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk