Defining Alias Templates
Explore how to define alias templates in C++ to create simpler, meaningful type names. Understand the use of 'using' declarations over typedef, and learn techniques for alias templates at namespace and class scope, including handling specialization limitations with class templates.
We'll cover the following...
In C++, an alias is a name used to refer to a type that has been previously defined, whether a built-in type or a user-defined type. The primary purpose of aliases is to give shorter names to types that have a long name or provide semantically meaningful names for some types. This can be done either with a typedef declaration or with a using declaration (the latter was introduced in C++11). Here are several examples using typedef:
In this example, index_t is an alias for int, NameValueList is an alias for std::vector<std::pair<int, std::string>>, while fn_ptr is an alias for the type of a pointer to a function that returns an ...