From 1fea63acc752aa09bc6fc3d05b5b69d699202b60 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 15 May 2024 11:11:35 +0200 Subject: Add a default typed template parameter to functions --- modules/codec/c++/interface.hpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'modules/codec/c++') diff --git a/modules/codec/c++/interface.hpp b/modules/codec/c++/interface.hpp index 19dc145..f77c05f 100644 --- a/modules/codec/c++/interface.hpp +++ b/modules/codec/c++/interface.hpp @@ -3,25 +3,42 @@ #include #include + #include "schema.hpp" #include "data.hpp" namespace saw { -template +template class function; +namespace impl { +template +struct FuncTypeHelper { + using Type = std::function(data, Ctx)>; +}; + template -class function, Encode> { +struct FuncTypeHelper { + using Type = std::function(data)>; +}; +} + +template +class function, Encode, Context> { private: - std::function(data)> func_; + typename impl::FuncTypeHelper::Type func_; public: template function(Func func): func_{std::move(func)} {} - error_or> call(data req){ + error_or> call(data req, Context ctx = {}){ + if constexpr (std::is_same_v){ return func_(std::move(req)); + } else { + return func_(std::move(req), ctx); + } } }; -- cgit v1.2.3