Namespace aliases - cppreference.com

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.

Syntax

namespacealias_name = ns_name;(1) namespacealias_name = ::ns_name;(2) namespacealias_name = nested_name::ns_name;(3) namespacealias_name = splice-specifier;(4) (since C++26)alias_name- an identifier ns_name- a (possibly

qualified

) identifier that names a namespace or namespace alias splice-specifier- a

splice specifier

that designates a namespace that is not the global namespace Explanation

The new alias alias_name provides an alternate method of accessing ns_name or the namespace designated by splice-specifier(since C++26).

alias_name must be a name not previously used. alias_name is valid for the duration of the scope in which it is introduced.

Keywords

namespace

Example

Run this code

#include<iostream>namespacefoo{namespacebar{namespacebaz{intqux=42;}}}namespacefbz=foo::bar::baz;intmain(){std::cout<<fbz::qux<<'\n';}Output:

42 See also