Skip to content
Snippets Groups Projects
Commit 24fb093f authored by Adrien Béraud's avatar Adrien Béraud
Browse files

map_utils: add vectorFromMapValues and findByValue

parent a0cfd94c
No related branches found
No related tags found
No related merge requests found
......@@ -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_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment