From b6dcee91d8fb56ca0ae5a1f401054903062c271f Mon Sep 17 00:00:00 2001
From: Fabian Reister <fabian.reister@kit.edu>
Date: Wed, 12 Jan 2022 09:17:48 +0100
Subject: [PATCH] swapping args of simox::alg::apply

---
 SimoxUtility/algorithm/apply.hpp | 7 ++++---
 SimoxUtility/color/ColorMap.h    | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/SimoxUtility/algorithm/apply.hpp b/SimoxUtility/algorithm/apply.hpp
index 85029e5b9..b28f06ac1 100644
--- a/SimoxUtility/algorithm/apply.hpp
+++ b/SimoxUtility/algorithm/apply.hpp
@@ -11,10 +11,12 @@ namespace simox::alg
 
     template <typename ValueIn, typename UnaryOp>
     std::vector<std::invoke_result_t<UnaryOp, ValueIn>>
-    apply(const UnaryOp& op, const std::vector<ValueIn>& vector)
+    apply(const std::vector<ValueIn>& vector, const UnaryOp& op)
     {
         using ValueOut = std::invoke_result_t<UnaryOp, ValueIn>;
         std::vector<ValueOut> result;
+        result.reserve(vector.size());
+
         std::transform(vector.begin(), vector.end(), std::back_inserter(result), op);
         return result;
     }
@@ -22,7 +24,7 @@ namespace simox::alg
 
     template <typename Key, typename ValueIn, typename UnaryOp>
     std::map<Key, std::invoke_result_t<UnaryOp, ValueIn>>
-    apply(const UnaryOp& op, const std::map<Key, ValueIn>& map)
+    apply(const std::map<Key, ValueIn>& map, const UnaryOp& op)
     {
         using ValueOut = std::invoke_result_t<UnaryOp, ValueIn>;
         std::map<Key, ValueOut> result;
@@ -35,4 +37,3 @@ namespace simox::alg
 
 
 }
-
diff --git a/SimoxUtility/color/ColorMap.h b/SimoxUtility/color/ColorMap.h
index 951b83cae..06b6bdea3 100644
--- a/SimoxUtility/color/ColorMap.h
+++ b/SimoxUtility/color/ColorMap.h
@@ -91,13 +91,13 @@ namespace simox::color
         template <typename V>
         std::vector<Color> operator()(const std::vector<V>& vector) const
         {
-            return simox::alg::apply(*this, vector);
+            return simox::alg::apply(vector, *this);
         }
         /// Apply this colormap to a map's values.
         template <typename K, typename V>
         std::map<K, Color> operator()(const std::map<K, V>& map) const
         {
-            return simox::alg::apply(*this, map);
+            return simox::alg::apply(map, *this);
         }
 
 
-- 
GitLab