Boost logo

Boost :

From: Dill, John (john-dill_at_[hidden])
Date: 2004-04-14 08:57:41

> > 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
> it
> can act on a copy. However, once you know the mechanism, you would be
> irritated by such constraints.
> Thorsten

I agree with Thorsten's point. The first inclination when binding a function with a reference is that the arguments passed to that bind functor is actually passed by reference. That is what you are actually saying in your bind statement. While having pass-by-value may be more convenient and occur more often, the counter-intuitiveness of the semantics will lead to subtle bugs in people's code who misunderstand or forget bind's behavior in this area.

It is not a matter of reducing the power of bind or "hand-holding" as has been said, but enforcing the semantics of what the programmer is actually saying. If you are binding to a reference argument, you should not need a ref( arg ) to say that the argument really is a reference. If you are binding to a reference, and want to pass by value, let the programmer type the extra 5-10 characters and explicitly say that he's changing the semantics of the bind. I personally like "bind( f, value( i ) )" myself. All that would need to be done is to introduce a argument_traits type class that will wrap references with a reference_wrapper, and also provide a value() wrapper.

If you are binding often to a reference and want to pass-by-value, you might need to re-evaluate your interface.

Just my 2 cents.


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