Boost logo

Boost :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2002-03-08 13:42:45

> > What is your opinion about the semantics?
> I'm not sure... I'd say it's about 60/40 in favor of the Bind behavior, but
> neither is "right" since some people will always expect the opposite.

We chose this implementation as it treats all arguments of the bind
expression similarly, the first argument is no exception.
And it is more flexible.
> The "Bind way" to evaluate the first argument is
> bind(apply<R>(), _1, _2);
> where apply(f, a1, ..., aN) returns f(a1, ..., aN). (In
> boost/bind/apply.hpp.)

Does this cover something like:

int add(int a, int b) { return a+b; }
int mul(int a, int b) { return a*b; }

int(*)(int, int) add_or_mul(bool x) {
  return x ? add : mul;

bool condition; int i; int j;
bind(bind(&add_or_mul, _1), _2, _3)(condition, i, j);

> bind(foo, 1, 2) will fail. bind(foo, _1)(1, 2) will succeed. There is a
> difference between the two; the first is a common error and is detected (at
> 'bind time', i.e. even without a call) but the latter is, at least in my
> experience, usually deliberate and rarely accidental.
I don't see much difference in the nature of the errors (if the latter
then is an error or not).
In any case, as there is an easy way to achive the discarding of
the arguments, we do not lose much flexibility with the BLL way.


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