Add comments for field set helpers
This commit is contained in:
parent
816c5db9f5
commit
32f3fccf17
1 changed files with 38 additions and 6 deletions
|
@ -6,13 +6,29 @@ import utempl;
|
||||||
|
|
||||||
namespace larra::xmpp::utils {
|
namespace larra::xmpp::utils {
|
||||||
|
|
||||||
template <typename T, typename... Fs>
|
template <typename T, typename R>
|
||||||
struct FieldDescription {
|
|
||||||
utempl::Tuple<Fs...> tuple;
|
|
||||||
|
|
||||||
template <typename R>
|
|
||||||
constexpr auto GetType(R(T::* ptr)) -> 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>
|
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([] {
|
||||||
|
@ -52,7 +68,7 @@ struct FieldDescription {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename... Fs>
|
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)...}};
|
return {.tuple = {std::forward<Fs>(fs)...}};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,6 +79,22 @@ consteval auto CreateFieldsDescription(Rs(T::*... ptr)) {
|
||||||
} | utempl::kSeq<sizeof...(Rs)>;
|
} | 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 {
|
export struct FieldSetHelper {
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue