In the stlport library, I saw this code:
namespace std { }
namespace __std_alias = std;
1. Are they trying to nullify the standard std namespace in the first line?
2. Why in the world would they use a longer alias name in place of the original name?
You need the namespace “in scope” before you can declare an alias to it. The empty
namespace std {}informs the compiler that the namespace exists. Then they can create an alias to it.There are reasons for creating aliases besides creating a shortcut. For example, you can define a macro to “rename” the namespace — consider the effect of
#define std STLPORT_std. Having a alias allows you to access the original namespace provided that you play the correct ordering games with header files.