#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
typedef std::vector< std::pair<int, std::string>> Categories;
int main()
{
std::map<std::string, Categories> cats;
cats["key1"] = {std::make_pair(1, "pair1"), std::make_pair(1, "pair2"), std::make_pair(1, "par3")};
cats["key2"] = {std::make_pair(2, "pair1"), std::make_pair(2, "pair2")};
cats["key3"] = {std::make_pair(3, "pair1")};
std::cout << "Range based loop \n";
for(const auto& it: cats)
{
std::cout << it.first << " = "; // keys
for(const auto& ve: it.second) // values vec
std::cout << ve.first << "-" << ve.second << "\t";
std::cout << std::endl;
}
std::cout << "\nIterator loop \n";
std::map<std::string, Categories>::const_iterator it;
std::vector< std::pair<int, std::string>>::const_iterator curr_val_it;
for(it = cats.cbegin(); it != cats.cend(); ++it)
{
std::cout << it->first << " = "; // keys
for(curr_val_it = it->second.cbegin(); curr_val_it != it->second.cend(); ++curr_val_it )
std::cout << curr_val_it->first << "-" << curr_val_it->second << "\t"; // values vec
std::cout << std::endl;
}
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8aXRlcmF0b3I+Cgp0eXBlZGVmIHN0ZDo6dmVjdG9yPCBzdGQ6OnBhaXI8aW50LCBzdGQ6OnN0cmluZz4+IENhdGVnb3JpZXM7CgppbnQgbWFpbigpCnsKICAgc3RkOjptYXA8c3RkOjpzdHJpbmcsIENhdGVnb3JpZXM+IGNhdHM7CgogICBjYXRzWyJrZXkxIl0gPSB7c3RkOjptYWtlX3BhaXIoMSwgInBhaXIxIiksIHN0ZDo6bWFrZV9wYWlyKDEsICJwYWlyMiIpLCBzdGQ6Om1ha2VfcGFpcigxLCAicGFyMyIpfTsKICAgY2F0c1sia2V5MiJdID0ge3N0ZDo6bWFrZV9wYWlyKDIsICJwYWlyMSIpLCBzdGQ6Om1ha2VfcGFpcigyLCAicGFpcjIiKX07CiAgI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