paxdiablo
paxdiablo

Reputation: 882296

Multi-tier namespace specification in C++

A client of mine has coding standards that call for namespaces need to be defined with all individual names and braces on separate lines. This leads to the vertical-space-consuming (a point which is annoying some developers on the team):

namespace MyCompany
{
    namespace MyProduct
    {
        namespace ThisFunctionalUnit
        {
            :
        }
    }
}

Given that the vast majority of their code consists of files totally wrapped in the sort of hierarchy seen above, they could minimise the problem by allowing:

namespace MyCompany { namespace MyProduct { namespace ThisFunctionalUnit
{
    :
}}} // namespace MyCompany::MyProduct::ThisFunctionalUnit

That comes with other issues but is workable. However, it seems to me the whole issue would go away if C++ allowed multi-tier specification of namespaces in the first place, along the lines of:

namespace MyCompany::MyProduct::ThisFunctionalUnit
{
    :
}

My question is really, why doesn't C++ allow this? It can't be because :: can be used within namespace levels since that would render using namespace unworkable.

Does anyone know why this is the case, or whether it's likely to be redressed?

Upvotes: 0

Views: 83

Answers (1)

David
David

Reputation: 28178

Nested namespace definitions are allowed now, in C++17:

namespace A::B::C {

It's equivalent to:

namespace A { namespace B { namespace C {

Upvotes: 1

Related Questions