Using type aliases

Sometimes the names of types can become quite cumbersome. If you use nested namespaces, the name of a type includes all of the namespaces used. If you define parameterized types (examples used so far in this chapter are vector and tuple), the parameters increase the name of the type. For example, earlier we saw a container for the names and birth years of musicians:

    // #include <string>     // #include <vector>     // #include <tuple>      vector<tuple<string, int> > beatles;

Here, the container is a vector and it holds items that are tuple items, each of which will hold a string and an integer. To make the type easier to use you could define a preprocessor symbol:

    #define name_year tuple<string, int>

Now you can use name_year ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.