Update counter

This commit is contained in:
sha512sum 2024-06-26 02:46:37 +00:00
parent 86b24ea926
commit 69b8276361

View file

@ -1,22 +1,21 @@
#pragma once #pragma once
#include <utempl/loopholes/core.hpp> #include <utempl/loopholes/core.hpp>
#include <cstddef> #include <cstddef>
#include <tuple>
namespace utempl::loopholes { namespace utempl::loopholes {
namespace impl { namespace impl {
template <typename Tag, auto Value> template <typename Tag, std::size_t Value>
struct TagWithValue {}; struct TagWithValue {};
template <auto I = 0, typename Tag, typename... Ts, auto = Injector<TagWithValue<Tag, I>{}>{}> template <typename Tag, std::size_t I, typename... Ts>
constexpr auto Counter(...) { consteval auto Counter() -> std::size_t {
return I; if constexpr(requires{Magic(Getter<TagWithValue<Tag, I>{}>{});}) {
}; return Counter<Tag, I + 1, Ts...>();
};
template <auto I = 0, typename Tag, typename... Ts> return (std::ignore = Injector<TagWithValue<Tag, I>{}, 0>{}, I);
consteval auto Counter(std::size_t arg) requires Injected<TagWithValue<Tag, I>{}, Ts...> {
return Counter<I + 1, Tag, Ts...>(arg);
}; };
} // namespace impl; } // namespace impl;
@ -24,10 +23,7 @@ consteval auto Counter(std::size_t arg) requires Injected<TagWithValue<Tag, I>{}
template < template <
typename Tag, typename Tag,
typename... Ts, typename... Ts,
std::size_t R = impl::Counter<0, Tag, Ts...>(std::size_t{}) std::size_t R = impl::Counter<Tag, 0, Ts...>()
#if defined __clang__
- 1
#endif
> >
consteval auto Counter(auto...) -> std::size_t { consteval auto Counter(auto...) -> std::size_t {
return R; return R;