|
Boost Users : |
From: Rodolfo Lima (rodolfo_at_[hidden])
Date: 2006-11-28 19:26:13
> You are right, it doesn't work; lambda's operator->* seems a pretty odd
> beast. Interesting that nobody has discovered its quirks so far. FWIW, the
> syntax above is how it should work in order to be usable. Lambda currently
> implements
That's how I thought it would work. Is it difficult to make lambda work this
way?
> You can use the above syntax with boost::bind and overload get_pointer for
> aux, but this won't work for lambda::bind or std::tr1::bind. Can't you
> just
> add operator* to aux? A raw pointer can escape via ptr, so adding a way to
> dereference the pointer doesn't seem to make it any more dangerous.
No, I can't add operator* to aux because its ptr member function actually
returns a shared_ptr that it gets from another source. If this source
doesn't own the shared_ptr, ptr will return a shared_ptr with use_count 1.
If we define this member as
T &operator*() { return *ptr(); }
it would return a reference to an object that is already deleted by
~shared_ptr. By using only ->* or -> returning a shared_ptr, it will last
until the end of the member function call.
> It works for your example and returns 5. When I add an aux_ptr class with
> a
My example doesn't compile with g++ 4.1.1, which compiler are you using?
>
>>> function<int(const aux_ptr &)> f = &aux::a;
>
> works through it, too.
What if aux::a has a parameter? I'd like to do:
function<int(const aux &)> f = (&_1->*&aux::a)(x,y,z);
Thanks,
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