Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-06-19 10:11:32

----- Original Message -----
From: "Ed Brey" <edbrey_at_[hidden]>

> Just to clarify, the problem you're alluding to is in code of the form:
> namespace boost {
> namespace sub {
> class foo;
> }
> using namespace sub;
> }
> which would be written with the intent of allowing both "boost::foo
> bar;" and "using namespace boost::sub; foo bar;" with minimal work on
> the library implementer's side. As you point out, this breaks some
> forms of lookup.
> The tuples submission doesn't follow this pattern: rather, it has the
> nested namespace, but no using directive, so the equivalent of
> boost::foo is not supported. It appears that the user is encouraged to
> use "using namespace boost::tuple(s);", which seems fine as long as
> usage is within a user's function or namespace, both of which are
> reasonably likely.

Hmm. I would much prefer, in that case, to see tuple directly in boost.
Subnamespaces should be for domain libraries (e.g. boost::python,
boost::graph), as we have discussed earlier
( Tuples are not a domain,
but a utility.

Wouldn't it be better for the user to write:
  using boost::tuple;
  using namespace boost::tuple;

no lookup issues; less typing.

> If the user don't perform such a using directive and the namespace
> matches the class name, the code will have fragments like this:
> "boost::tuple::tuple mytup" or at least "tuple::tuple mytup". This
> isn't necessarily a problem: I use "string.string", "array.array", and
> "glob.glob" (although these are functions, not classes) in Python
> without any confusion, but my experience in that regard is brief, and
> hence I was curious what more experienced users of non-unique names have
> found.

I find that unconfusing and workable, but ugly. I like scopes to narrow the
domain as they are traversed, which string.string and glob.glob don't do.
More importantly, scoping isn't buying you any protection in this case:
"glob" is already taken at global scope, just like the name "tuple" would be
taken in namespace boost. Why make people reach in further just to grab the
piece they want?

> For the record, if the dual scope of the pattern listed above were
> desired (so that both "boost::foo" and "using namespace sub" worked), it
> could be accomplished using this pattern, without encuring any lookup
> problems (AFAIK):
> namespace boost {
> class foo;
> namespace sub {
> using foo;
> }
> }
> This is more work for the implementer, since a "using name" definition
> must be entered by hand for each name to be placed namespace sub, but
> it's still not too bad.

Or, I suppose, this would also work?

namespace boost {
    namespace sub {
        class foo;
    using sub::foo;

Anyway, that would be fine with me, if you want to do it.


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