Type Aliases – typedef and using
If you have used the std::string class, then you have been using an alias. There are a few template classes related to strings that need to implement the same functionality. But the type representing a character is different. For example, for std::string, the representation is char, while std::wstring uses wchar_t. There are several others for char16_t and char32_t. Any variation in the functionality will be managed through traits or template specialization.
Prior to C++11, this would have been aliased from the std::basic_string base class, as follows:
namespace std {
typedef basic_string<char> string;
}
This does two main things:
- Reduces the amount of typing required to declare the variable. This is a simple case, but when you declare a unique pointer to a map of strings to object, it can get very long and you will make errors:
typedef std::unique_ptr<std::map<std::string,myClass>> UptrMapStrToClass;
- Improves the readability...