Add comments for every method in field set helpers

This commit is contained in:
sha512sum 2024-08-27 19:15:55 +00:00
parent 32f3fccf17
commit 7619b0c339

View file

@ -25,10 +25,16 @@ constexpr auto GetType(R(T::* ptr)) -> R;
// return kUtils.With(&SomeStruct::field2, std::forward<Self>(self), std::move(field2)); // With field2 // return kUtils.With(&SomeStruct::field2, std::forward<Self>(self), std::move(field2)); // With field2
// } // }
// }; // };
template <typename T, typename... Fs> export template <typename T, typename... Fs>
struct FieldsDescription { struct FieldsDescription {
utempl::Tuple<Fs...> tuple; utempl::Tuple<Fs...> tuple; /*!< tuple for field ptrs */
/* Method accepting field index, self and new value for field and returns object with new field value
*
* \param I field index for object T
* \param self old object
* \param value new value for field
* \return T with new field value and values from self
*/
template <std::size_t I, typename Self, typename Value> template <std::size_t I, typename Self, typename Value>
constexpr auto With(Self&& self, Value&& value) const constexpr auto With(Self&& self, Value&& value) const
requires([] { requires([] {
@ -50,6 +56,13 @@ struct FieldsDescription {
} | utempl::kSeq<sizeof...(Fs)>; } | utempl::kSeq<sizeof...(Fs)>;
}; };
/* Method accepting field pointer, self and new value for field and returns object with new field value
*
* \param ptr field ptr for object T
* \param self old object
* \param value new value for field
* \return T with new field value and values from self
*/
template <typename Self, typename Value, typename Type> template <typename Self, typename Value, typename Type>
constexpr auto With(Type(T::* ptr), Self&& self, Value&& value) const constexpr auto With(Type(T::* ptr), Self&& self, Value&& value) const
requires std::is_constructible_v<Type, decltype(value)> requires std::is_constructible_v<Type, decltype(value)>
@ -72,10 +85,15 @@ consteval auto CreateFieldsDescriptionHelper(Fs&&... fs) -> FieldsDescription<T,
return {.tuple = {std::forward<Fs>(fs)...}}; return {.tuple = {std::forward<Fs>(fs)...}};
}; };
/* Method accepting field ptrs and returns FieldsDescription
*
* \param ptrs field ptrs
* \return FieldsDescription with T and ptrs
*/
export template <typename T, typename... Rs> export template <typename T, typename... Rs>
consteval auto CreateFieldsDescription(Rs(T::*... ptr)) { consteval auto CreateFieldsDescription(Rs(T::*... ptrs)) {
return [&](auto... is) { return [&](auto... is) {
return CreateFieldsDescriptionHelper<T>(ptr...); return CreateFieldsDescriptionHelper<T>(ptrs...);
} | utempl::kSeq<sizeof...(Rs)>; } | utempl::kSeq<sizeof...(Rs)>;
}; };
@ -96,6 +114,13 @@ consteval auto CreateFieldsDescription(Rs(T::*... ptr)) {
// }; // };
export struct FieldSetHelper { export struct FieldSetHelper {
/* Method accepting field index, self and new value for field and returns object with new field value
*
* \param I field index for object T
* \param self old object
* \param value new value for field
* \return T with new field value and values from self
*/
template <std::size_t I, typename Self, typename Value> template <std::size_t I, typename Self, typename Value>
static constexpr auto With(Self&& self, Value&& value) static constexpr auto With(Self&& self, Value&& value)
requires([] { requires([] {
@ -117,6 +142,13 @@ export struct FieldSetHelper {
} | utempl::kSeq<boost::pfr::tuple_size_v<T>>; } | utempl::kSeq<boost::pfr::tuple_size_v<T>>;
}; };
/* Method accepting field name, self and new value for field and returns object with new field value
*
* \param FieldName field name for object T
* \param self old object
* \param value new value for field
* \return T with new field value and values from self
*/
template <utempl::ConstexprString FieldName, typename Self, typename Value> template <utempl::ConstexprString FieldName, typename Self, typename Value>
static constexpr auto With(Self&& self, Value&& value) -> decltype(With<[] { static constexpr auto With(Self&& self, Value&& value) -> decltype(With<[] {
auto names = boost::pfr::names_as_array<std::decay_t<Self>>(); auto names = boost::pfr::names_as_array<std::decay_t<Self>>();