diff --git a/examples/src/attributes.cpp b/examples/src/attributes.cpp new file mode 100644 index 0000000..337c9c5 --- /dev/null +++ b/examples/src/attributes.cpp @@ -0,0 +1,27 @@ +#include +#include + +template +struct AttributeData { + T value; +}; + + +#define MY_ATTRIBUTE(type, ...) GENERIC_ATTRIBUTE(AttributeData{__VA_ARGS__}) + + +ATTRIBUTE_STRUCT(SomeStruct, + MY_ATTRIBUTE(int, .value = 2); + int field; + SKIP_ATTRIBUTE(); + int field2; + MY_ATTRIBUTE(std::string, .value = "HEY!") + std::string field3; +); + +static_assert(SomeStruct::GetAttribute<0>().value == 2); +static_assert(SomeStruct::GetAttribute<2>().value == "HEY!"); + + + +auto main() -> int {}; diff --git a/examples/src/make.cpp b/examples/src/make.cpp new file mode 100644 index 0000000..82f2534 --- /dev/null +++ b/examples/src/make.cpp @@ -0,0 +1,5 @@ +#include + +auto main() -> int { + constexpr auto arr = utempl::TupleMaker>::Make(); +}; diff --git a/include/utempl/attributes.hpp b/include/utempl/attributes.hpp new file mode 100644 index 0000000..82e9035 --- /dev/null +++ b/include/utempl/attributes.hpp @@ -0,0 +1,48 @@ +#include +#include + + +namespace utempl { + + + +namespace impl { + +struct AttributesTag {}; + +template +struct AttributesCounterTag {}; + + +template ()> +struct CurrentSetter {}; + + +} // namespace impl + + + + + +#define ATTRIBUTE_STRUCT(name, ...) struct name { \ +static_assert((::utempl::impl::CurrentSetter(), true)); \ +template \ +static consteval auto GetAttribute(); __VA_ARGS__ } + +struct NoInfo {}; + +#define GENERIC_ATTRIBUTE(value) \ + template <> \ + consteval auto GetAttribute< \ + ::utempl::loopholes::Counter< \ + ::utempl::impl::AttributesCounterTag())::Type \ + >, \ + decltype([]{}) >()>() { return value; } + +#define SKIP_ATTRIBUTE() GENERIC_ATTRIBUTE(::utempl::NoInfo{}) + + +} // namespace utempl diff --git a/include/utempl/meta_info.hpp b/include/utempl/meta_info.hpp index ace4259..74c6097 100644 --- a/include/utempl/meta_info.hpp +++ b/include/utempl/meta_info.hpp @@ -70,6 +70,16 @@ consteval auto GetTypeListForTag() { return impl::GetTypeListForTag(TypeList{}); }; +template < + typename Tag, + typename... Ts, + auto I = utempl::loopholes::CountValue() - 1 +> +consteval auto GetCurrentTagType() { + return Magic(utempl::loopholes::Getter{}>()); +}; + + /* static_assert(kTypeId == 0); static_assert(kTypeId == 1);