From 5c7a65bc1853c418093a6e496d0fdf29498d36d5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 2 Sep 2026 00:28:29 +0200 Subject: [PATCH] Parameters: allow to pass an initial parameter value ...and in addition check that the defined value type is consistent with the list of pre-configured `BaseTypes` Signed-off-by: Ichthyostega --- src/lib/par/parameter.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/par/parameter.hpp b/src/lib/par/parameter.hpp index cacd25897..ae2cdb507 100644 --- a/src/lib/par/parameter.hpp +++ b/src/lib/par/parameter.hpp @@ -31,6 +31,7 @@ #include "lib/par/disposition.hpp" #include "lib/polymorphic-value.hpp" +#include "lib/meta/typelist-util.hpp" #include @@ -70,6 +71,16 @@ namespace par { static Builder forType() { return {}; } + template + static Builder> + forValue (VAL&& initVal) + { + using PayloadType = std::decay_t; + return forType() + .withValue (std::forward (initVal)); + } + + protected: template Parameter (IMP* typeTag, ARGS&&... args) @@ -81,6 +92,9 @@ namespace par { template class Parameter::Builder { + static_assert (meta::isInList() + ,"Only some fixed base data types are supported as Parameter value type."); + VAL initVal_{}; public: @@ -92,6 +106,14 @@ namespace par { Parameter resParam{typeTag, std::move (initVal_)}; return resParam; } + + template + Builder&& + withValue (X&& initVal) + { + initVal_ = std::forward (initVal); + return std::move(this); + } };