Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2004-04-13 08:10:00

"Peter Dimov" <pdimov_at_[hidden]> wrote in message
> Thorsten Ottosen wrote:
> > Hi Peter,
> >
> > [snp]
> >> Yes, of course it is possible to reject the example. But I don't
> >> want to reject it. It's useful.
> >
> > Ok. Could you present an example?
> This feature of bind is used to create stateful function objects. In a
> "real" lambda facility it corresponds to a local static variable:
> for_each( first, last, lambda(v) { static int x = 0; f(v, ++x); } );
> The bind equivalent is
> for_each( first, last, bind( f, _1, bind(incr, 0) ) );

ok, but couldn't incr() just be defined as 'int incr( int i ) { return i +
1; }' ?

Anyway, it is not the possibility of having "local static" data in function
we are arguing about, its about what to pass that data to.

> Bind's emphasis is on usefulness, not hand-holding.

good frase :-)

>Its learning curve is
> inherently steep and more importantly, it simply cannot be flattened by
> making bind less useful.

I guess the current design gives maximal power; so it it seems ok. Requering
that the
user calls

bind( f, local_copy( i ) )

would document that the programmer knows that f takes a reference, but that
can act on a copy. However, once you know the mechanism, you would be
irritated by such constraints.



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