-1

I want to get all keys from a collection, is there a standard way to do this?

std::unordered_map<std::string, size_t> map;
auto keys = map.get_keys();
  • What special do you expect from `auto keys`? Your `map` is already a kind of collection of keys. The vector of keys can be collected by `for(auto v: map) keys.push_back(v.first);` – Askold Ilvento Dec 21 '20 at 21:29
  • You can always iterate over all the key value pairs using a range based loop? For what would you need all keys lsited separately? – πάντα ῥεῖ Dec 21 '20 at 21:32

1 Answers1

2
for( const auto& n : map ) {
        std::cout << "Key:[" << n.first << "]\n";
}
Manuel
  • 2,526
  • 1
  • 13
  • 17