Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-08-20 14:07:40


> I think that Bind is a good library and should be included into boost, subject to dealing with the following two issues:
>
> (1) There are names that are not in the boost namespace. This needs to be changed to avoid a conflict. The existence of an anonymous namespace does not help. Imagine an author of some other library, say Bond, decided to use names like Bind does, and a piece of user code happens to use both libraries. The result would be
>
> #include <boost/bind.hpp>
> #include <james/bond.hpp>
> ...
> boost::bind(f, _0)(x);
> james::bond(g, _0, _0, _7)(a,b,c,d,e,f,g,h);
>
> with the _0 being ambiguous. Normally, a user who is interested in protecting himself from such a conflict can use namespaces to prevent this, especially since the above code may come from two modules that were at one time independent. Bind has taken that option away from the user. This is the same sin (only to a less degree) as defining ones own pseudo-keywords using macros (e.g. signal).

> A less in intrusive solution is to define _0, _1, ... _7, ref, and cref, in namespace boost, then create a subnamespace called, say "argument", which declares all those names using using declarations. Then a user can simply write "using namespace boost::argument;" if unqualified _0 is desired, but the boost will is not forced on the just by virtue of bind.hpp being included.

I also had this concern with an anonymous namespace. I don't think
putting any names whatsoever in an anonymous namespace at global scope
should be allowed for a header that might be included by other headers.
Given template code, I think that bind.hpp meets that definition.

I think the suggested solution is not a bad one, although I might put
the full names in the boost::argument namespace directly, but making
them visible again in the boost namespace, since then the qualified
name helps indicate these otherwise somewhat mysteriously named
variables' purpose.

 However, given the importance of this library to users of standard
algorithms, I think we will find that ease-of-use is very important. I
would like to suggest that in this case, it might be appropriate to
supply two headers, one of which is the base, use-fully-qualified bind
header; and the second includes the base bind and then pulls these
_digit names (and perhaps even boost::bind itself) into the visible
namespace. Then implementation files can use the no-thought-required
version, and header files can use the other, and either fully qualify
with boost::_1, or in a local scope use the incantation Greg suggests.

George Heintzelman
georgeh_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk