From 32f3fccf178ac85a6d8842b03f06b3e4662e880c Mon Sep 17 00:00:00 2001 From: sha512sum Date: Tue, 27 Aug 2024 18:52:39 +0000 Subject: [PATCH] Add comments for field set helpers --- src/lib/utils.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/lib/utils.cpp b/src/lib/utils.cpp index a7cde5d..2681150 100644 --- a/src/lib/utils.cpp +++ b/src/lib/utils.cpp @@ -6,12 +6,28 @@ import utempl; namespace larra::xmpp::utils { -template -struct FieldDescription { - utempl::Tuple tuple; +template +constexpr auto GetType(R(T::* ptr)) -> R; - template - 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 +// constexpr auto Field1(this Self&& self, std::string field1) -> SomeStruct { +// return kUtils.With<0>(std::forward(self), std::move(field1)); // Return new object with field1 value from field1 and with +// // field2 value from self.field2 +// } +// template +// constexpr auto Field2(this Self&& self, std::string field2) -> SomeStruct { +// return kUtils.With(&SomeStruct::field2, std::forward(self), std::move(field2)); // With field2 +// } +// }; +template +struct FieldsDescription { + utempl::Tuple tuple; template constexpr auto With(Self&& self, Value&& value) const @@ -52,7 +68,7 @@ struct FieldDescription { }; template -consteval auto CreateFieldsDescriptionHelper(Fs&&... fs) -> FieldDescription...> { +consteval auto CreateFieldsDescriptionHelper(Fs&&... fs) -> FieldsDescription...> { return {.tuple = {std::forward(fs)...}}; }; @@ -63,6 +79,22 @@ consteval auto CreateFieldsDescription(Rs(T::*... ptr)) { } | utempl::kSeq; }; +// Field set helper +// struct SomeStruct { +// std::string field1; +// std::string field2; +// +// template +// auto Field1(this Self&& self, std::string field1) -> SomeStruct { +// return FieldSetHelper::With<0>(std::forward(self), std::move(field1)); // Return new object with field1 value from field1 +// // and with field2 value from self.field2 +// } +// template +// auto Field2(this Self&& self, std::string field2) -> SomeStruct { +// return FieldSetHelper::With<"field2">(std::forward(self), std::move(field2)); // With field2 +// } +// }; + export struct FieldSetHelper { template static constexpr auto With(Self&& self, Value&& value)