From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-15 10:08:36
From: "Douglas Gregor" <gregod_at_[hidden]>
> I see now what you mean. You want the function library to essentially hold
> reference/pointer to the function object you pass in and not ever make a
> of it.
> If this were to be an addition to the function library, would you have a
> preferred form? The only form I can think of would be to reuse the "ref"
> function used by bind, so one would have:
> void foo(boost::function<...> func);
> template<typename F>
> void bar(F f)
> foo(ref(f)); // boost::function won't allocate any memory or copy f
Before you go ahead and implement this, I suggest we consider adding a
separate 'fref' to ref.hpp.
It would be just like 'ref' except it would define, instead of 'operator
T&', a bunch of forwarding operator()s.
The reasons for this are:
* fref() would be useful for dealing with standard algorithms that tend to
make copies of the function object and generally don't like stateful
* ref(x), in a broader, lambda library context, is a function object that
(regardless of the arguments passed to it) returns a reference to x, like in
ref(x) += _1;
So there is a conflict between ref(f)(x) meaning f(x) or just f.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk