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)