In C++, what is a "namespace alias"?

Martin B picture Martin B · Jul 31, 2009 · Viewed 55.7k times · Source

What is a "namespace alias" in C++? How is it used?

Answer

Martin B picture Martin B · Jul 31, 2009

A namespace alias is a convenient way of referring to a long namespace name by a different, shorter name.

As an example, say you wanted to use the numeric vectors from Boost's uBLAS without a using namespace directive. Stating the full namespace every time is cumbersome:

boost::numeric::ublas::vector<double> v;

Instead, you can define an alias for boost::numeric::ublas -- say we want to abbreviate this to just ublas:

namespace ublas = boost::numeric::ublas;


ublas::vector<double> v;