Fix attributes
This commit is contained in:
parent
5b402e48dd
commit
58134818ef
2 changed files with 14 additions and 25 deletions
|
@ -26,12 +26,13 @@ static_assert(utempl::GetAttributes<SomeStruct>() ==
|
||||||
|
|
||||||
struct SomeOtherStruct {
|
struct SomeOtherStruct {
|
||||||
static_assert(utempl::OpenStruct<SomeOtherStruct>());
|
static_assert(utempl::OpenStruct<SomeOtherStruct>());
|
||||||
utempl::FieldAttribute<int, int> field1;
|
utempl::FieldAttribute<int, utempl::TypeList<int>> field1;
|
||||||
utempl::FieldAttribute<int> field2;
|
utempl::FieldAttribute<int> field2;
|
||||||
utempl::FieldAttribute<std::string, void> field3;
|
utempl::FieldAttribute<std::string, utempl::TypeList<void>> field3;
|
||||||
static_assert(utempl::CloseStruct());
|
static_assert(utempl::CloseStruct());
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(utempl::GetAttributes<SomeOtherStruct>() == utempl::Tuple{utempl::kTypeList<int>, utempl::NoInfo{}, utempl::kTypeList<void>});
|
static_assert(utempl::GetAttributes<SomeOtherStruct>() ==
|
||||||
|
utempl::Tuple{utempl::kTypeList<int>, utempl::kTypeList<>, utempl::kTypeList<void>});
|
||||||
|
|
||||||
auto main() -> int {};
|
auto main() -> int {};
|
||||||
|
|
|
@ -35,25 +35,12 @@ export struct NoInfo {
|
||||||
consteval auto operator==(const NoInfo&) const -> bool = default;
|
consteval auto operator==(const NoInfo&) const -> bool = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename... Ts>
|
export template <typename T,
|
||||||
struct FieldAttributeData {
|
typename O = TypeList<>,
|
||||||
using Type = TypeList<Ts...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct FieldAttributeData<> {
|
|
||||||
using Type = NoInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T,
|
|
||||||
typename... Ts,
|
|
||||||
auto f = [] {},
|
auto f = [] {},
|
||||||
typename Current = decltype(GetCurrentTagType<impl::AttributesTag, decltype(f)>())::Type,
|
typename Current = decltype(GetCurrentTagType<impl::AttributesTag, decltype(f)>())::Type,
|
||||||
auto = AddTypeToTag<impl::AttributesCounterTag<Current>, typename FieldAttributeData<Ts...>::Type, decltype(f)>()>
|
auto = AddTypeToTag<impl::AttributesCounterTag<Current>, O, decltype(f)>()>
|
||||||
consteval auto FieldAttributeHelper() -> T;
|
using FieldAttribute = T;
|
||||||
|
|
||||||
export template <typename... Ts>
|
|
||||||
using FieldAttribute = decltype(FieldAttributeHelper<Ts...>());
|
|
||||||
|
|
||||||
export template <typename T, auto f = [] {}, bool R = (loopholes::CountValue<impl::AttributesCounterTag<T>, decltype(f)>() > 0)>
|
export template <typename T, auto f = [] {}, bool R = (loopholes::CountValue<impl::AttributesCounterTag<T>, decltype(f)>() > 0)>
|
||||||
concept HasAttributes = R;
|
concept HasAttributes = R;
|
||||||
|
@ -74,8 +61,9 @@ consteval auto GetAttributes()
|
||||||
export template <typename T>
|
export template <typename T>
|
||||||
consteval auto GetAttributes() {
|
consteval auto GetAttributes() {
|
||||||
constexpr auto I = loopholes::CountValue<impl::AttributesCounterTag<T>>();
|
constexpr auto I = loopholes::CountValue<impl::AttributesCounterTag<T>>();
|
||||||
return [](auto... is) {
|
return
|
||||||
return utempl::Tuple{typename decltype(Magic(loopholes::Getter<MetaInfoKey<is, impl::AttributesCounterTag<T>>{}>{}))::Type{}...};
|
[](auto... is) -> Tuple<typename decltype(Magic(loopholes::Getter<MetaInfoKey<*is, impl::AttributesCounterTag<T>>{}>{}))::Type...> {
|
||||||
|
return {};
|
||||||
} | kSeq<I>;
|
} | kSeq<I>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue