Namespace aliases
From cppreference.com
Namespace aliases allow the programmer to define an alternate name for a namespace.
They are commonly used as a convenient shortcut for long or deeply-nested namespaces.
Contents |
Syntax
namespace Template:sparam = Template:sparam;
|
(1) | ||||||||
namespace Template:sparam = ::Template:sparam;
|
(2) | ||||||||
namespace Template:sparam = Template:sparam::Template:sparam;
|
(3) | ||||||||
Explanation
The new alias Template:sparam provides an alternate method of accessing Template:sparam.
Template:sparam must be a name not previously used. Template:sparam is valid for the duration of the scope in which it is introduced.
Example
#include <iostream> namespace foo { namespace bar { namespace baz { int qux = 42; } } } namespace fbz = foo::bar::baz; int main() { std::cout << fbz::qux << '\n'; }
Output:
42