From 24fb093f6cd86e3263aa8d8107f8f85295ca2009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Tue, 15 Apr 2014 14:10:26 -0400 Subject: [PATCH] map_utils: add vectorFromMapValues and findByValue --- daemon/src/map_utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/daemon/src/map_utils.h b/daemon/src/map_utils.h index eed64396c3..98046b8362 100644 --- a/daemon/src/map_utils.h +++ b/daemon/src/map_utils.h @@ -35,12 +35,30 @@ #include <map> namespace map_utils { + template <typename M, typename V> void vectorFromMapKeys(const M &m, V &v) { for (typename M::const_iterator it = m.begin(); it != m.end(); ++it) v.push_back(it->first); } + +template <typename M, typename V> +void vectorFromMapValues(const M &m, V &v) +{ + for (typename M::const_iterator it = m.begin(); it != m.end(); ++it) + v.push_back(it->second); +} + +template <typename M, typename V> +typename M::const_iterator +findByValue(const M &m, V &v) { + for (typename M::const_iterator it = m.begin(); it != m.end(); ++it) + if (it->second == v) + return it; + return m.cend(); +} + } #endif // MAP_UTILS_H_ -- GitLab