aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/vcpkg_Util.h
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-04-01 01:09:34 -0700
committerRobert Schumacher <roschuma@microsoft.com>2017-04-01 01:11:51 -0700
commit74f788d04f2ff8ce66302b6be401ec9b7e85a42f (patch)
tree248492633c926e8046e7a1610607209758f48bdd /toolsrc/include/vcpkg_Util.h
parent74fbd3acd5d2128e94dad2a0a5f705e93bb49e9a (diff)
downloadvcpkg-74f788d04f2ff8ce66302b6be401ec9b7e85a42f.tar.gz
vcpkg-74f788d04f2ff8ce66302b6be401ec9b7e85a42f.zip
[vcpkg] Replace explicit bulk operations with fmap
Diffstat (limited to 'toolsrc/include/vcpkg_Util.h')
-rw-r--r--toolsrc/include/vcpkg_Util.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h
new file mode 100644
index 000000000..4ebb2a802
--- /dev/null
+++ b/toolsrc/include/vcpkg_Util.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <vector>
+#include <utility>
+
+namespace vcpkg::Util
+{
+ template<class Cont, class Func>
+ using FmapOut = decltype(std::declval<Func>()(std::declval<Cont>()[0]));
+
+ template<class Cont, class Func, class Out = FmapOut<Cont, Func>>
+ std::vector<Out> fmap(const Cont& xs, Func&& f)
+ {
+ using O = decltype(f(xs[0]));
+
+ std::vector<O> ret;
+ ret.reserve(xs.size());
+
+ for (auto&& x : xs)
+ ret.push_back(f(x));
+
+ return ret;
+ }
+} \ No newline at end of file