From 8f5d503d808b8ab134d864ec865041f2e12b1c05 Mon Sep 17 00:00:00 2001 From: Fabian Reister <fabian.reister@kit.edu> Date: Sat, 15 Jan 2022 22:12:28 +0100 Subject: [PATCH] simox::alg::apply for sets --- SimoxUtility/algorithm/apply.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SimoxUtility/algorithm/apply.hpp b/SimoxUtility/algorithm/apply.hpp index b28f06ac1..8c80b6638 100644 --- a/SimoxUtility/algorithm/apply.hpp +++ b/SimoxUtility/algorithm/apply.hpp @@ -2,6 +2,7 @@ #include <algorithm> #include <map> +#include <set> #include <type_traits> #include <vector> @@ -21,6 +22,18 @@ namespace simox::alg return result; } + template <typename ValueIn, typename UnaryOp> + std::vector<std::invoke_result_t<UnaryOp, ValueIn>> + apply(const std::set<ValueIn>& set, const UnaryOp& op) + { + using ValueOut = std::invoke_result_t<UnaryOp, ValueIn>; + std::vector<ValueOut> result; + result.reserve(set.size()); + + std::transform(set.begin(), set.end(), std::back_inserter(result), op); + return result; + } + template <typename Key, typename ValueIn, typename UnaryOp> std::map<Key, std::invoke_result_t<UnaryOp, ValueIn>> -- GitLab