eile
eile

Reputation: 1153

C++ nested namespace alias possible?

I have the following code I'm refactoring:

namespace Foo
{
    namespace Bar { ...classes... }
}

Bar is now moving into a new top-level namespace, but I'ld like to keep API compatibility:

namespace Pi { ...classes... } // refactored Foo::Bar
namespace Foo { namespace Bar = Pi; } // API compatibility

This doesn't work, since it aliases Foo::Bar::Class to Foo::Pi::Class, but not Pi::Class. Is there a way (short of a macro or typedef'ing all Pi classed) to achieve what I want?

Upvotes: 4

Views: 835

Answers (2)

enobayram
enobayram

Reputation: 4708

Oops, you want it the other way round:

namespace Foo {
  namespace Bar {
     using namespace Pi;
  }
}

Upvotes: 2

CB Bailey
CB Bailey

Reputation: 793369

If I understand correctly, this should do what you need. It means that any lookup in Foo::Bar will find names in ::Pi.

namespace Pi {}
namespace Foo { namespace Bar { using namespace Pi; } }

Obviously, this won't preserve binary compatibility.

Upvotes: 3

Related Questions