diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-14 14:31:17 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-14 14:31:45 -0700 |
| commit | 55f554eea1c1c5135329ae18ab4f50661ba7c6bf (patch) | |
| tree | 910548c351861f42cec4c3dff982c964f3bf1e1d | |
| parent | 392b3a50ead4092ea3688385b492e5455c5f6ced (diff) | |
| download | vcpkg-55f554eea1c1c5135329ae18ab4f50661ba7c6bf.tar.gz vcpkg-55f554eea1c1c5135329ae18ab4f50661ba7c6bf.zip | |
Introduce Util::group_by()
| -rw-r--r-- | toolsrc/include/vcpkg_Util.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h index bb93413ed..978407bd8 100644 --- a/toolsrc/include/vcpkg_Util.h +++ b/toolsrc/include/vcpkg_Util.h @@ -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); + } + } }
\ No newline at end of file |
