In C++, what is a “namespace alias”?

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;

Leave a Comment