diff --git a/examples/str_exam.cpp b/examples/str_exam.cpp index bdfe12d..a924f9c 100644 --- a/examples/str_exam.cpp +++ b/examples/str_exam.cpp @@ -99,6 +99,11 @@ int main() kv1.setValue(7.7, snplib_serialization_params_t{}, si, snplib_serialization_params_t{}, 100, snplib_serialization_params_t{}); + std::println("key = '{}'", kv1.key()); + std::println("value = '{}'", kv1.value()); + std::println("valueSeq = '{}'\n", kv1.valueSeq()); + + si = std::string{"dekjlwe3"}; kv1.setValue(snplib_serialization_params_t{}, 7.7, si, 100); @@ -106,6 +111,15 @@ int main() std::println("value = '{}'", kv1.value()); std::println("valueSeq = '{}'\n", kv1.valueSeq()); + si = "WER"; + kv1.appendValue(snplib_serialization_params_t{}, 77.77, si, 1111); + + std::println("key = '{}'", kv1.key()); + std::println("value = '{}'", kv1.value()); + std::println("valueSeq = '{}'\n", kv1.valueSeq()); + + + snplib_random_string_generator_t<> rstr_gen; std::println("\n\n"); diff --git a/include/snipplib/utils/snplib_keyvalue_expr.h b/include/snipplib/utils/snplib_keyvalue_expr.h index 5a11833..9a11335 100644 --- a/include/snipplib/utils/snplib_keyvalue_expr.h +++ b/include/snipplib/utils/snplib_keyvalue_expr.h @@ -290,43 +290,12 @@ public: } - // value1, ser-pars1, value2, ser-pars2, ..., valueN, ser-parsN - template - requires(mutableContent && sizeof...(ValSerParPairTs) >= 4 && (sizeof...(ValSerParPairTs) % 2 == 0) && - !snplib_serialization_params_c>>) - error_t setValue(ValSerParPairTs&&... pairs) - { - constexpr auto f = [](std::index_sequence) { - using args_t = std::tuple; - - return ((snplib_serializable_c> && - snplib_serialization_params_c>) && - ...); - }(std::make_index_sequence{}); - - _valueSeq.clear(); // to trigger the first call to setValue - - return [this](this auto&& self, auto&& v1, auto&& sp1, auto&&... prs) -> error_t { - auto err = appendValue(std::forward(v1), std::forward(sp1)); - if (err) { - return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument)); - } - - if constexpr (sizeof...(prs)) { - return std::forward(self)(std::forward(prs)...); - } - - return {}; - }(std::forward(pairs)...); - } - - // value1, ser-pars1, value2, ser-pars2, ..., valueN, ser-parsN // or // common-ser-pars, value1, value2, ..., valueN template requires(mutableContent && sizeof...(ArgTs) > 1) - error_t setValue(ArgT&& arg, ArgTs&&... args) + error_t appendValue(ArgT&& arg, ArgTs&&... args) { static constexpr size_t NARGS = sizeof...(ArgTs) + 1; @@ -352,8 +321,6 @@ public: static_assert(is_val_spar_pairs || is_val_seq, "Unsupported input parameter types!"); - _valueSeq.clear(); // to trigger the first call to setValue - if constexpr (is_val_spar_pairs) { return [this](this auto&& self, auto&& v1, auto&& sp1, auto&&... prs) -> error_t { auto err = appendValue(std::forward(v1), std::forward(sp1)); @@ -387,106 +354,14 @@ public: } } + template + requires(mutableContent && sizeof...(ArgTs) > 1) + error_t setValue(ArgT&& arg, ArgTs&&... args) + { + _valueSeq.clear(); // to trigger the first call to setValue - // // common-ser-pars, value1, value2, ..., valueN - // template - // requires(mutableContent && sizeof...(ValueTs) > 1) - // error_t setValue(SParT sparams, ValueTs&&... values) - // { - // _valueSeq.clear(); // to trigger the first call to setValue - - // return [sp = std::move(sparams), this](this auto&& self, auto&& tp) -> error_t { - // using tp_t = std::remove_cvref_t; - - // if constexpr (I < std::tuple_size_v) { - // auto err = appendValue( - // std::forward>(std::get(std::forward(tp))), - // std::move(sp)); - // if (err) { - // return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument)); - // } - - // return std::forward(self).template operator()(std::forward(tp)); - // } - - // return {}; - // }(std::forward_as_tuple(std::forward(values)...)); - // } - - // value1, ser-pars1, value2, ser-pars2, ..., valueN, ser-parsN - // or - // value1, value2, ..., valueN, common-ser-pars - // template - // requires(mutableContent && sizeof...(ArgTs) > 2) - // error_t setValue(ArgTs&&... args) - // { - // constexpr auto is_val_spar_pairs = [](std::index_sequence) { - // using args_t = std::tuple; - - // return ((snplib_serializable_c> && - // snplib_serialization_params_c>) && - // ...); - // }(std::make_index_sequence{}); - - // using v_args_t = snplib_tuple_except_last_t; - - // constexpr auto is_val_seq = [](std::index_sequence) { - // return (snplib_serializable_c> && ...); - // }(std::make_index_sequence>{}); - - // static_assert(is_val_spar_pairs || is_val_seq, "Unsupported input parameter types!"); - - // _valueSeq.clear(); // to trigger the first call to setValue - - // if constexpr (is_val_spar_pairs) { - // return [this](this auto&& self, auto&& v1, auto&& sp1, auto&&... prs) -> error_t { - // auto err = appendValue(std::forward(v1), std::forward(sp1)); - // if (err) { - // return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument)); - // } - - // if constexpr (sizeof...(prs)) { - // return std::forward(self)(std::forward(prs)...); - // } - - // return {}; - // }(std::forward(args)...); - // } else { // value sequence with trailing common serialization parameters - // static_assert(snplib_serialization_params_c>, - // "The last input parameter must satisfy to 'snplib_serialization_params_c' requirement!"); - - // auto make_vals_tuple = [... args = std::forward(args)]() mutable { - // return [tp = std::forward_as_tuple(std::forward(args)...)]( - // std::index_sequence) mutable { - // return std::forward_as_tuple( - // std::forward>(std::get(tp))...); - // }(std::make_index_sequence{}); - // }; - - - // return [spar = std::forward(args)...))>>( - // std::get(std::forward_as_tuple(std::forward(args)...))), - // this](this auto&& self, auto&& tp) -> error_t { - // using tp_t = std::remove_cvref_t; - - // if constexpr (I < std::tuple_size_v) { - // auto err = appendValue( - // std::forward>(std::get(std::forward(tp))), - // std::forward(spar)); - // if (err) { - // return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument)); - // } - - // return std::forward(self).template operator()( - // std::forward(tp)); - // } - - // return {}; - // }(make_vals_tuple()); - // } - // } - + return appendValue(std::forward(arg), std::forward(args)...); + } template