From 059dc4308ac731d2b3c324166d87b8d527b9d217 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 15 May 2024 13:36:15 +0200 Subject: Fixed compilation of attached ctx data --- modules/codec/c++/interface.hpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'modules/codec/c++') diff --git a/modules/codec/c++/interface.hpp b/modules/codec/c++/interface.hpp index f77c05f..d6d02a3 100644 --- a/modules/codec/c++/interface.hpp +++ b/modules/codec/c++/interface.hpp @@ -35,6 +35,7 @@ public: error_or> call(data req, Context ctx = {}){ if constexpr (std::is_same_v){ + (void) ctx; return func_(std::move(req)); } else { return func_(std::move(req), ctx); @@ -50,17 +51,17 @@ public: }; -template +template class interface; -template -class interface, Names>...>, Encode> { +template +class interface, Names>...>, Encode, Context> { public: using Schema = schema::Interface,Names>...>; private: - std::tuple, Encode>...> funcs_; + std::tuple, Encode, Context>...> funcs_; public: - interface(function, Encode>... funcs): + interface(function, Encode, Context>... funcs): funcs_{std::move(funcs)...} {} @@ -84,6 +85,7 @@ public: > , Encode + , Context >& get(){ return std::get::value>(funcs_); } @@ -103,26 +105,31 @@ public: Lit, Names... >::value , Requests...>::type - , Encode> req + , Encode> req, + Context ctx = {} ){ - return get().call(std::move(req)); + if constexpr (std::is_same_v) { + (void) ctx; + return get().call(std::move(req)); + }else{ + return get().call(std::move(req), ctx); + } } - }; -template +template struct function_factory { template - static function create(Func func){ - return function{std::move(func)}; + static function create(Func func){ + return function {std::move(func)}; } }; -template +template struct interface_factory { template - static interface create(Func... func){ - return interface{std::move(func)...}; + static interface create(Func... func){ + return interface{std::move(func)...}; } }; } -- cgit v1.2.3