nested namespaces in C++

Started by
2 comments, last by krez 20 years, 2 months ago
i am prototyping a large project, and i am using nested namespaces to categorize a lot of the stuff:

namespace ProjectName
{
  namespace SubNamespace
  {
  ...
  };
  namespace OtherSubNamespace
  {
  ...
  };
}; 
i have to type out the two "namespace" lines, and also the two closing brackets. is there a "shortcut" way of doing this? i tried:

namespace ProjectName::SubNamespace
  {
  ...
  };
 
but that doesn''t work. it isn''t too important; i am curious mainly.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Advertisement
I don''t know of any "real" quick ways of doing it, but you can always cheat using macros:
#define NAMESPACE2_BEGIN(outer, inner) \  namespace outer { \    namespace inner {#define NAMESPACE2_END() \    } \  }// To use them:NAMESPACE2_BEGIN(ProjectName, SubNamespace)  // ...NAMESPACE2_END()

Or something like that.

I just write out the namespaces and just neglect to tab them out for large sections (the files I do that to have everything in a single namespace, so it''s not too confusing to read without the tabbing), it''s really not that bad . I think the only C++ project I''m working on has namespaces nested as deeply as 5 levels in parts (most of that stuff is just implementations of interfaces though)...

thanks for the tip, although i don''t think it is worth that much effort (i am blocking things together in separate files anyway, so it only happens once per source file).
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
It''s done like this:
namespace alias = ProjectName::SubNamespace;

This topic is closed to new replies.

Advertisement