#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
template<template <typename...> class MAP, class KEY, class VALUE>
std::vector<KEY>
keys(const MAP<KEY, VALUE>& map)
{
std::vector<KEY> result;
result.reserve(map.size());
for(const auto& it : map){
result.emplace_back(it.first);
}
return result;
}
template<template <typename...> class MAP, class KEY, class VALUE>
std::vector<VALUE>
values(const MAP<KEY, VALUE>& map)
{
std::vector<VALUE> result;
result.reserve(map.size());
for(const auto& it : map){
result.emplace_back(it.second);
}
return result;
}
int main() {
std::map<std::string, int> string_to_int;
// std::unordered_map<std::string, int> string_to_int;
string_to_int.emplace("foo", 12);
string_to_int.emplace("bar", 34);
cout << "Keys:" << endl;
for(const auto& k : keys(string_to_int)){
cout << k << endl;
}
cout << "Values:" << endl;
for(const auto& v : values(string_to_int)){
cout << v << endl;
}
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlPHRlbXBsYXRlIDx0eXBlbmFtZS4uLj4gY2xhc3MgTUFQLCBjbGFzcyBLRVksIGNsYXNzIFZBTFVFPgpzdGQ6OnZlY3RvcjxLRVk+CmtleXMoY29uc3QgTUFQPEtFWSwgVkFMVUU+JiBtYXApCnsKCXN0ZDo6dmVjdG9yPEtFWT4gcmVzdWx0OwoJcmVzdWx0LnJlc2VydmUobWFwLnNpemUoKSk7Cglmb3IoY29uc3QgYXV0byYgaXQgOiBtYXApewoJCXJlc3VsdC5lbXBsYWNlX2JhY2soaXQuZmlyc3QpOwoJfQoJcmV0dXJuIHJlc3VsdDsKfQoKdGVtcGxhdGU8dGVtcGxhdGUgPHR5cGVuYW1lLi4uPiBjbGFzcyBNQVAsIGNsYXNzIEtFWSwgY2xhc3MgVkFMVUU+CnN0ZDo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