|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-02-14 14:56:32
Douglas Gregor wrote:
> We've discussed making boost::ref/boost::cref work for arbitrary
> functions
> objects before. I just committed a version of ref.hpp that supports
> this
> ability to the sandbox. With this code, you can write:
>
> std::transform(c.begin(), c.end(), out, boost::ref(f));
>
> or, if you don't want the return type deduced, specify it as in
> Boost.Bind:
>
> std::transform(c.begin(), c.end(), out, boost::ref<float>(f));
I'm not sure whether that last part is a good idea.
The ref "vision" has been that in a perfect world,
ref(f)(x, y);
is exactly the same as
F & rf = f;
rf(x, y);
and the best way to accomplish that is a core change that enables all
conversion operators to be considered in function calls (currently only
conversion operators to pointers to functions are considered.)
With this in mind, the implementation of ref(f) that relies on the typedefs
to approximate the above is fine (although it might be overkill to consider
anything beyond result_type and perhaps sig) but the ref<R> syntax doesn't
rhyme. We need to keep in mind that ref<Base>(derived) and ref<int const>(5)
are valid today.
The bind<R>(ref(f), _1) workaround is always an option when the natural
syntax fails.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk