summaryrefslogtreecommitdiff
path: root/modules/codec
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-06-12 17:15:34 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-06-12 17:15:34 +0200
commite2a7609028346c3b776a424c9be848e49d3a0e2e (patch)
treeed4d8adf8b82a6442514da467406c6bc3d3fc312 /modules/codec
parente4e49a117702945066e3e279fa0f005200400cb7 (diff)
Working on reference types in std::function deduction
Diffstat (limited to 'modules/codec')
-rw-r--r--modules/codec/c++/id_map.hpp8
-rw-r--r--modules/codec/c++/interface.hpp11
2 files changed, 14 insertions, 5 deletions
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<typename T, typename Encoding>
+template<typename T, typename Encoding, typename Storage>
class id_map final {
private:
/**
* Container which stores the primary data
*/
- std::vector<data<T,Encoding>> data_;
+ std::vector<data<T,Encoding,Storage>> 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<id<T>> insert(data<T,Encoding> val) noexcept {
+ error_or<id<T>> insert(data<T,Encoding,Storage> 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<data<T,Encoding>*> find(const id<T>& val){
+ error_or<data<T,Encoding,Storage>*> find(const id<T>& val){
if(val.get_value() >= data_.size()){
return make_error<err::not_found>("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<data<Response, Encode, Storage>> call(data<Request, Encode, Storage> req, Context ctx = {}){
+ error_or<data<Response, Encode, Storage>> call(data<Request, Encode, Storage>& req, Context ctx = {}){
+ if constexpr (std::is_same_v<Context, void_t>){
+ (void) ctx;
+ return func_(req);
+ } else {
+ return func_(req, ctx);
+ }
+ }
+
+ error_or<data<Response, Encode, Storage>> call(data<Request, Encode, Storage>&& req, Context ctx = {}){
if constexpr (std::is_same_v<Context, void_t>){
(void) ctx;
return func_(std::move(req));