Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ nested namespace alias possible?

Tags:

c++

namespaces

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?

like image 507
eile Avatar asked Sep 01 '25 17:09

eile


1 Answers

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.

like image 168
CB Bailey Avatar answered Sep 04 '25 07:09

CB Bailey