mirror of
https://github.com/jslightham/cpp-utils.git
synced 2026-03-09 18:12:26 +01:00
Initial commit
This commit is contained in:
19
Map.h
Normal file
19
Map.h
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
#ifndef MAP_UTIL_H
|
||||
#define MAP_UTIL_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
// Get vector of values from an unordered_map
|
||||
template <typename K, typename V, typename H>
|
||||
std::vector<V> map_to_values(const std::unordered_map<K, V, H> &map) {
|
||||
std::vector<V> out;
|
||||
out.reserve(map.size());
|
||||
for (auto const &[key, value] : map) {
|
||||
out.push_back(value);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif // MAP_UTIL_H
|
||||
Reference in New Issue
Block a user