diff options
Diffstat (limited to 'common/util.h')
-rw-r--r-- | common/util.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/util.h b/common/util.h index 9512bd40..07ebac75 100644 --- a/common/util.h +++ b/common/util.h @@ -112,6 +112,24 @@ template <typename K, typename V> std::map<K, V *> sorted(const std::unordered_m return retVal; }; +// Wrap an unordered_map, and allow it to be iterated over sorted by key +template <typename K, typename V> std::map<K, V &> sorted_ref(std::unordered_map<K, V> &orig) +{ + std::map<K, V &> retVal; + for (auto &item : orig) + retVal.emplace(std::make_pair(item.first, std::ref(item.second))); + return retVal; +}; + +// Wrap an unordered_map, and allow it to be iterated over sorted by key +template <typename K, typename V> std::map<K, const V &> sorted_cref(const std::unordered_map<K, V> &orig) +{ + std::map<K, const V &> retVal; + for (auto &item : orig) + retVal.emplace(std::make_pair(item.first, std::ref(item.second))); + return retVal; +}; + // Wrap an unordered_set, and allow it to be iterated over sorted by key template <typename K> std::set<K> sorted(const std::unordered_set<K> &orig) { |