Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-06-19 08:45:38


From: "David Abrahams" <david.abrahams_at_[hidden]>

> > [Ed Brey]
> > Aaargh. Using the plural is out of sync with other namespaces and
such
> > constructs I've come across, but your concern seems quite valid. I
know
> > that Python tends to have namespaces (in the form of modules) with
> > functions by the same name. Is there any wisdom to be gleened from
> > experience in that corner?
> > [Gary]
> > Sorry, We don't mean to cause you any anguish. But will bow to the
wisdom
> of
> > practice. Dave A. do you have a comment here?
>
> Only this: using-directives used to do namespace composition don't
really
> work, because various kinds of lookup don't treat the names
transparently.
> If that's what you've got (and I haven't looked at the code), you'd be
> better off sticking this directly in namespace boost and doing away
with the
> nesting. Here's a previous conversation to that effect:
> http://groups.yahoo.com/group/boost/message/2075

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.

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.

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.

> Oh, hello again, Ed! Is this familiar territory?

Do you mean namespaces or tuples? Namespaces, definitely - they seem to
keep reappearing. Tuples is new to me, but unlike the past few
libraries, this one seemed like one that I could digest well enough to
provide reasonably helpful comments on in the small time I have for
reviewing (master's degree night classes in progress). Of course,
expected likelihood of use also plays a motivational factor. :-)


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