Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-02-13 10:12:15

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));
> Features of this implementation:
> - Return type deduction (discussed below)
> - Argument type deduction (discussed below)
> - Able to handle function objects that have multiple arities (e.g.,
> can be
> invoked with 0 or 2 arguments)

That's very nice!

> ------Compatibility------
> This version of ref.hpp is backwards-compatible with the existing
> version of
> ref.hpp on a compiler that can handle the new ref.hpp (needs partial
> specialization and proper SFINAE handling). At some point I'll write a
> stripped-down version that other compilers can handle.

I tried to do this once and failed. It's hard to make operator() work on
deficient compilers (esp. the zero-arg version that is not a template)
without breaking ref(x) where x is not a function object.

Boost list run by bdawes at, gregod at, cpdaniel at, john at