Introduce Util::group_by()

This commit is contained in:
Alexander Karatarakis 2017-04-14 14:31:17 -07:00
parent 392b3a50ea
commit 55f554eea1
1 changed files with 10 additions and 0 deletions

View File

@ -39,4 +39,14 @@ namespace vcpkg::Util
{
return std::find_if_not(cont.cbegin(), cont.cend(), pred);
}
template<class K, class V, class Container, class Func>
void group_by(const Container& cont, std::map<K, std::vector<const V*>>* output, Func f)
{
for (const V& element : cont)
{
K key = f(element);
(*output)[key].push_back(&element);
}
}
}