Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-01-16 14:48:56

On Wednesday 16 January 2002 02:23 pm, you wrote:
> >>>>> "David" == David Abrahams <david.abrahams_at_[hidden]> writes:
> David> I think this is the wrong forum for that question. Maybe you
> want David> comp.std.c++?
> If it is generally believed that pass by reference is the preferred
> design, then perhaps boost could supply a set of functions:
> generate_ref, transform_ref, etc.

A Boost solution was discussed where boost::reference_wrapper would gain the
ability to pass-through function calls. Then one could use something like:

transform(v.begin, v.end(), back_inserter(out), ref(stateful_function_object))

It's not implemented yet, but you aren't out of luck: Boost.Function and
Boost.Bind both allow their function objects to be wrapped via ref() or
cref(), so the equivalent to the above using Boost.Bind, for instance, would

transform(v.begin(), v.end(), back_inserter(out),

where R is the return type of stateful_function_object.

Boost.Function works similarly, and one could use:

transform(v.begin(), v.end(), back_inserter(out),
                  boost::function<R, Arg1>(ref(stateful_function_object)));

where R is the return type and Arg1 is the argument type of

The Boost.Bind function is what you probably want, unless
stateful_function_object happens to be coming from somewhere else and you're
suffering from template bloat because of it.


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