Obtaining list of keys and values from unordered_map

后端 未结 4 1647
陌清茗
陌清茗 2020-12-13 08:22

What is the most efficient way of obtaining lists (as a vector) of the keys and values from an unordered_map?

For concreteness, suppose the

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 08:53

    In STL there is no built-in method to get all keys or values from a map.

    There is no different to iterate a unordered map or regular map, the best way is to iterate it and collect key or value to a vector.

    You can write a template function to iterate any kind of map.

提交回复
热议问题