Topic: Namespace private context, was Nested namespaces definition


Author: hattons@globalsymmetry.com ("Steven T. Hatton")
Date: Thu, 15 Apr 2004 17:09:30 +0000 (UTC)
Raw View
adeht wrote:

> ""Steven T. Hatton"" <hattons@globalsymmetry.com> wrote in message
> news:P4WdnbJgqdLx8-DdRVn-vA@speakeasy.net...
>> This is something Mathematica supports for its packages. I've wondered
>> the
>> same thing.  I haven't proposed this for C++ simply because I had not
>> come
>> across a use for it in C++.  How would such a construct benefit the
>> language?
>
> I didn't search, sorry about that. Here's the proposal:
> http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1524.htm
>
> You can read about the possible uses for that in the paper.

I guess I didn't understand what you were suggesting.  My response was
addressing the "Private" concept suggested by your example.  In
Mathematica, there is something called a package which functions much like
a namespace in C++.  One feature is a mechanism to declare a private
context within a package. This is analogous to the private declaration
mechanism used in C++ classes.

More discussion of Mathematica packages can be found here:
http://documents.wolfram.com/v5/TheMathematicaBook/PrinciplesOfMathematica/ModularityAndTheNamingOfThings/2.7.10.html

This could conceivably be used in C++ to hide namespace local code that is
only needed internally to the namespace.  As I said, I haven't found a
compelling argument for suggesting this for C++, but since your example
hinted at such a thing, I thought it would be worth bringing to people's
attention.

And then there is the obvious 'protected' access specifier which might be
used to share implementation details with more deepley nested namespaces.
One implementation of this concept might look something like the following:

namespace nsA {
  private:
    //nsA local accessible
    namespace nsAPriv {
      //accessible to nsA only
    }
  protected:
    //accessable to nsA and anything under nsA
    namespace nsAProt {
      //accessible to nsA and namespaces under nsA
    }
  public:
    //the same as it is now
    namespace nsAPub {
      // can access nsA public and protected but not private
      // accessible to anything that can access nsA public
    }
}

Is it useful?  I can't offer a compelling argument for it. The concept,
however, seems worth considering.

--
STH
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]