From e2a7609028346c3b776a424c9be848e49d3a0e2e Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 12 Jun 2024 17:15:34 +0200 Subject: Working on reference types in std::function deduction --- modules/codec/c++/id_map.hpp | 8 ++++---- modules/codec/c++/interface.hpp | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'modules/codec') diff --git a/modules/codec/c++/id_map.hpp b/modules/codec/c++/id_map.hpp index bb31846..84c04e7 100644 --- a/modules/codec/c++/id_map.hpp +++ b/modules/codec/c++/id_map.hpp @@ -13,13 +13,13 @@ namespace saw { * Insert - O(1) * Erase - O(n) ? Dunno */ -template +template class id_map final { private: /** * Container which stores the primary data */ - std::vector> data_; + std::vector> data_; /** * Container which tracks free'd/fragmented elements within the * main container @@ -65,7 +65,7 @@ public: * Inserts an element into the container and returns either an id on success * or an error on failure. */ - error_or> insert(data val) noexcept { + error_or> insert(data val) noexcept { /// @todo Fix size_t and id base type if(free_ids_.empty()){ try { @@ -145,7 +145,7 @@ public: * Returns an error on failure and returns * a value pointer on success. */ - error_or*> find(const id& val){ + error_or*> find(const id& val){ if(val.get_value() >= data_.size()){ return make_error("ID is too large"); } diff --git a/modules/codec/c++/interface.hpp b/modules/codec/c++/interface.hpp index d55b415..0186f09 100644 --- a/modules/codec/c++/interface.hpp +++ b/modules/codec/c++/interface.hpp @@ -33,7 +33,16 @@ public: func_{std::move(func)} {} - error_or> call(data req, Context ctx = {}){ + error_or> call(data& req, Context ctx = {}){ + if constexpr (std::is_same_v){ + (void) ctx; + return func_(req); + } else { + return func_(req, ctx); + } + } + + error_or> call(data&& req, Context ctx = {}){ if constexpr (std::is_same_v){ (void) ctx; return func_(std::move(req)); -- cgit v1.2.3