It can be convenient, especially in template design, to create aliases for types. You can use
typedef to create aliases for template specializations:
// define three typedef aliasestypedef std::array<double, 12> arrd;typedef std::array<int, 12> arri;typedef std::array<std::string, 12> arrst;arrd gallons; // gallons is type std::array<double, 12>arri days; // days is type std::array<int, 12>arrst months; // months is type std::array<std::string, 12>
But if you find yourself writing code similar to the preceding
typedefs, over and over, you might wonder if you’ve forgotten some language feature that simplifies the task or if the language has forgotten to supply such a feature. In this case, C++11 provides a feature ...