This commit is contained in:
Timur A. Fatkhullin
2026-09-07 23:26:02 +03:00
parent ef798ddaf2
commit a2ef872d8d

View File

@@ -306,8 +306,8 @@ public:
_commands.emplace(std::move(id), std::forward<ET>(exec_func)); _commands.emplace(std::move(id), std::forward<ET>(exec_func));
} }
template <typename GT, typename ST, typename... UTs> template <typename GT, typename ST>
void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter, std::tuple<UTs...> = std::tuple<>{}) void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter)
{ {
using v_t = adclib_attr_value_deduced_t<GT, ST>; using v_t = adclib_attr_value_deduced_t<GT, ST>;
static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!"); static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!");
@@ -316,24 +316,34 @@ public:
static_assert(std::invocable<ST, v_t const&>, "Invalid setter argument type!"); static_assert(std::invocable<ST, v_t const&>, "Invalid setter argument type!");
} }
if constexpr (sizeof...(UTs)) { _attrGetter.push(id, attr_getter_t<v_t>(std::forward<GT>(getter)));
using tp_t = std::tuple<UTs...>; _attrSetter.push(id, attr_setter_t<v_t>(std::forward<ST>(setter)));
}
[&id, getter_cap = std::forward<GT>(getter), setter_cap = std::forward<ST>(setter), template <typename GT, typename ST, typename... UTs>
this]<size_t... Is>(std::index_sequence<Is...>) mutable { requires(sizeof...(UTs) > 0)
return std::apply( void addAttr(ATTR_ID_T id, GT&& getter, ST&& setter, std::tuple<UTs...>)
[this](auto&&... args) { addAttr(std::forward<decltype(args)>(args)...); }, {
std::tuple_cat( using v_t = adclib_attr_value_deduced_t<GT, ST>;
std::forward_as_tuple(id, std::forward<decltype(getter_cap)>(getter_cap), static_assert(!std::is_void_v<v_t>, "Getter and setter cannot be nullptr_t at the same time!");
std::forward<decltype(setter_cap)>(setter_cap)),
std::tuple_cat(std::forward_as_tuple( if constexpr (!std::is_null_pointer_v<GT> && !std::is_null_pointer_v<ST>) {
decltype(_attrGetter)::template trivial_conv_from<v_t, std::tuple_element_t<Is, tp_t>>, static_assert(std::invocable<ST, v_t const&>, "Invalid setter argument type!");
decltype(_attrGetter)::template trivial_conv_to<v_t, std::tuple_element_t<Is, tp_t>>)...)));
}(std::make_index_sequence<sizeof...(UTs)>{});
} else {
_attrGetter.push(id, std::forward<GT>(getter));
_attrSetter.push(id, std::forward<ST>(setter));
} }
using tp_t = std::tuple<UTs...>;
[&id, getter_cap = std::forward<GT>(getter), setter_cap = std::forward<ST>(setter),
this]<size_t... Is>(std::index_sequence<Is...>) mutable {
return std::apply(
[this](auto&&... args) { addAttr(std::forward<decltype(args)>(args)...); },
std::tuple_cat(
std::forward_as_tuple(id, std::forward<decltype(getter_cap)>(getter_cap),
std::forward<decltype(setter_cap)>(setter_cap)),
std::tuple_cat(std::forward_as_tuple(
decltype(_attrGetter)::template trivial_conv_from<v_t, std::tuple_element_t<Is, tp_t>>,
decltype(_attrGetter)::template trivial_conv_to<v_t, std::tuple_element_t<Is, tp_t>>)...)));
}(std::make_index_sequence<sizeof...(UTs)>{});
} }
// //
@@ -358,8 +368,8 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>; using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>; using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
// using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>; using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = std::invoke_result_t<from_fn_t>::value_type; // using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { u = v; }, "Invalid deduced user type!"); // static_assert(requires(v_t v, u_t u) { u = v; }, "Invalid deduced user type!");
@@ -381,8 +391,8 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>; using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>; using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
// using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>; using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = std::invoke_result_t<from_fn_t>::value_type; // using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { u = v; }, "Invalid deduced user type!"); // static_assert(requires(v_t v, u_t u) { u = v; }, "Invalid deduced user type!");
@@ -403,8 +413,8 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>; using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>; using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
// using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>; using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = std::invoke_result_t<from_fn_t>::value_type; // using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { v = u; }, "Invalid deduced user type!"); // static_assert(requires(v_t v, u_t u) { v = u; }, "Invalid deduced user type!");
@@ -427,8 +437,8 @@ public:
using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>; using from_fn_t = std::decay_t<std::tuple_element_t<I, TpT>>;
using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>; using to_fn_t = std::decay_t<std::tuple_element_t<I + 1, TpT>>;
// using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>; using u_t = adclib_attr_user_deduced_t<v_t, from_fn_t, to_fn_t>;
using u_t = std::invoke_result_t<from_fn_t>::value_type; // using u_t = std::invoke_result_t<from_fn_t>::value_type;
// static_assert(requires(v_t v, u_t u) { v = u; }, "Invalid deduced user type!"); // static_assert(requires(v_t v, u_t u) { v = u; }, "Invalid deduced user type!");
@@ -446,17 +456,19 @@ public:
}; };
}; };
std::apply([this](auto&&... args) { _attrGetter.push(std::forward<decltype(args)>(args)...); }, std::apply(
std::tuple_cat( [this](auto&&... args) { _attrGetter.push(std::forward<decltype(args)>(args)...); },
std::forward_as_tuple(id, std::forward<decltype(getter_cap)>(getter_cap)), std::tuple_cat(
std::tuple_cat(std::forward_as_tuple(gt_cnv_from_func.template operator()<2 * Is>(tp), std::forward_as_tuple(id, attr_getter_t<v_t>(std::forward<decltype(getter_cap)>(getter_cap))),
gt_cnv_to_func.template operator()<2 * Is>(tp))...))); std::tuple_cat(std::forward_as_tuple(gt_cnv_from_func.template operator()<2 * Is>(tp),
gt_cnv_to_func.template operator()<2 * Is>(tp))...)));
std::apply([this](auto&&... args) { _attrSetter.push(std::forward<decltype(args)>(args)...); }, std::apply(
std::tuple_cat( [this](auto&&... args) { _attrSetter.push(std::forward<decltype(args)>(args)...); },
std::forward_as_tuple(id, std::forward<decltype(setter_cap)>(setter_cap)), std::tuple_cat(
std::tuple_cat(std::forward_as_tuple(st_cnv_from_func.template operator()<2 * Is>(tp), std::forward_as_tuple(id, attr_setter_t<v_t>(std::forward<decltype(setter_cap)>(setter_cap))),
st_cnv_to_func.template operator()<2 * Is>(tp))...))); std::tuple_cat(std::forward_as_tuple(st_cnv_from_func.template operator()<2 * Is>(tp),
st_cnv_to_func.template operator()<2 * Is>(tp))...)));
}(std::make_index_sequence<NFUNCS / 2>{}); }(std::make_index_sequence<NFUNCS / 2>{});
} }