How to abbreviate long template type in C++

1 Answer

0 votes
#include <iostream>
#include <unordered_map>
#include <string>

// Abbreviation: alias for a long complex template type. 
using Cache = std::unordered_map<std::string, int>;

int main() {
    Cache scores;  // Using the abbreviation

    scores["Isla"] = 100;
    scores["Luke"] = 95;

    for (const auto& entry : scores) {
        std::cout << entry.first << ": " << entry.second << "\n";
    }
}



/*
run:

Luke: 95
Isla: 100

*/

 



answered Jul 9 by avibootz
...