Add comments for field set helpers

This commit is contained in:
sha512sum 2024-08-27 18:52:39 +00:00
parent 816c5db9f5
commit 32f3fccf17

View file

@ -6,13 +6,29 @@ import utempl;
namespace larra::xmpp::utils {
template <typename T, typename... Fs>
struct FieldDescription {
utempl::Tuple<Fs...> tuple;
template <typename R>
template <typename T, typename R>
constexpr auto GetType(R(T::* ptr)) -> R;
// Fields description
// struct SomeStruct {
// std::string field1;
// std::string field2;
// static constexpr /* FieldsDescription */ auto kUtils = CreateFieldsDescription(&SomeStruct::field1, &SomeStruct::field2);
//
// template <typename Self>
// constexpr auto Field1(this Self&& self, std::string field1) -> SomeStruct {
// return kUtils.With<0>(std::forward<Self>(self), std::move(field1)); // Return new object with field1 value from field1 and with
// // field2 value from self.field2
// }
// template <typename Self>
// constexpr auto Field2(this Self&& self, std::string field2) -> SomeStruct {
// return kUtils.With(&SomeStruct::field2, std::forward<Self>(self), std::move(field2)); // With field2
// }
// };
template <typename T, typename... Fs>
struct FieldsDescription {
utempl::Tuple<Fs...> tuple;
template <std::size_t I, typename Self, typename Value>
constexpr auto With(Self&& self, Value&& value) const
requires([] {
@ -52,7 +68,7 @@ struct FieldDescription {
};
template <typename T, typename... Fs>
consteval auto CreateFieldsDescriptionHelper(Fs&&... fs) -> FieldDescription<T, std::decay_t<Fs>...> {
consteval auto CreateFieldsDescriptionHelper(Fs&&... fs) -> FieldsDescription<T, std::decay_t<Fs>...> {
return {.tuple = {std::forward<Fs>(fs)...}};
};
@ -63,6 +79,22 @@ consteval auto CreateFieldsDescription(Rs(T::*... ptr)) {
} | utempl::kSeq<sizeof...(Rs)>;
};
// Field set helper
// struct SomeStruct {
// std::string field1;
// std::string field2;
//
// template <typename Self>
// auto Field1(this Self&& self, std::string field1) -> SomeStruct {
// return FieldSetHelper::With<0>(std::forward<Self>(self), std::move(field1)); // Return new object with field1 value from field1
// // and with field2 value from self.field2
// }
// template <typename Self>
// auto Field2(this Self&& self, std::string field2) -> SomeStruct {
// return FieldSetHelper::With<"field2">(std::forward<Self>(self), std::move(field2)); // With field2
// }
// };
export struct FieldSetHelper {
template <std::size_t I, typename Self, typename Value>
static constexpr auto With(Self&& self, Value&& value)