CKTIS / C++
Namespace alias
A namespace alias gives an existing namespace an additional, usually shorter name. It does not copy the namespace's members: both names refer to the same namespace.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
namespace alias_name = namespace_name;
namespace alias_name = outer::inner;The definition namespace alias_name = outer::inner; introduces a namespace alias. The final ; is required. The right-hand side must identify an existing namespace; it can also use a previously declared alias. Only namespace names are considered during name lookup in this context.
Members remain in their original namespace: alias_name::member accesses the same member as outer::inner::member. An alias does not copy data or automatically make the unqualified name member available in the surrounding scope. Do not confuse it with a using namespace directive or a type alias such as using Name = Type;.
In the example, cfg::limit = 7; changes the same variable subsequently read through application::settings::limit, so the expected output is 7 followed by a newline. The example targets C++23; the supplied page is an evolving working draft and may also contain later extensions.
Examples
#include <iostream>
namespace application::settings {
int limit = 3;
}
namespace cfg = application::settings;
int main() {
cfg::limit = 7;
std::cout << application::settings::limit << '\n';
}
Result
7
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.