Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-18 10:41:32

From: <brianjparker_at_[hidden]>
> I have been experimenting with the boost bind library, and in
> particular have modified it so that it passes arguments by value or
> reference as defined by the function's signature, so that ref() need
> not be used.

The fact that bind always takes its parameters by value and keeps an
internal copy (unless overriden by ref()) is a deliberate design decision.

The reasons are that:

* This behavior is more consistent and easier to define, teach, standardize

* You can tell from a glance at the bind expression which arguments are
by-value and which are by-ref.

* If you make bind autodetect, you need a mechanism to force pass-by-value
when the autodetection is wrong.

I agree that the autodetection can be convenient, especially for non-const
reference arguments.

> Also, one can now pass temporaries as arguments.

This is an interesting side effect; I haven't thought of this solution,
although it's a bit dangerous since you can pass a const lvalue to a
non-const reference this way AFAICS.

I haven't encountered a need to pass a temporary to bind so far, by the way.
I mostly use it with standard algorithms and boost::function that don't pass

> // todo: it would be nice to have 10 separate versions of bind_t depending
on arity
> i.e. each with a single operator()
> // -arity should be calculable at compile-time based on the largest value
of arg<N>
> found

This is deliberate, too. bind silently accepts and ignores extra arguments.

bind(f, _9); // ignores 8 arguments at the front
bind(f, _1); // should be able to ignore 8 arguments at the end, too

[Your helper functions at the end of bind.hpp are less useful on compilers
that don't allow &plus_f<int> due to core issue #115. This issue is evil.]

Peter Dimov
Multi Media Ltd.

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