Fix counter in gcc
This commit is contained in:
parent
59d590745c
commit
94c6f53b4f
2 changed files with 20 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
|||
#include <type_traits>
|
||||
#pragma once
|
||||
|
||||
namespace utempl::loopholes {
|
||||
|
@ -12,8 +13,18 @@ struct Injector {
|
|||
};
|
||||
|
||||
|
||||
template <auto I, typename...>
|
||||
concept Injected = requires{Magic(Getter<I>{});};
|
||||
template <auto, typename = void, typename... Ts>
|
||||
struct InjectedImpl {
|
||||
static constexpr bool value = false;
|
||||
};
|
||||
template <auto V, typename... Ts>
|
||||
struct InjectedImpl<V, std::void_t<decltype(Magic(Getter<V>{}))>, Ts...> {
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
template <auto I, typename... Ts>
|
||||
concept Injected = InjectedImpl<I, void, Ts...>::value;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,15 +7,15 @@ namespace utempl::loopholes {
|
|||
namespace impl {
|
||||
|
||||
template <typename Tag, auto Value>
|
||||
struct TagWithTalue {};
|
||||
struct TagWithValue {};
|
||||
|
||||
template <auto I = 0, typename Tag, typename... Ts, auto = Injector<TagWithTalue<Tag, I>{}>{}>
|
||||
template <auto I = 0, typename Tag, typename... Ts, auto = Injector<TagWithValue<Tag, I>{}>{}>
|
||||
constexpr auto Counter(...) {
|
||||
return I;
|
||||
};
|
||||
|
||||
template <auto I = 0, typename Tag, typename... Ts>
|
||||
consteval auto Counter(std::size_t arg) requires Injected<TagWithTalue<Tag, I>{}, Ts...> {
|
||||
consteval auto Counter(std::size_t arg) requires Injected<TagWithValue<Tag, I>{}, Ts...> {
|
||||
return Counter<I + 1, Tag, Ts...>(arg);
|
||||
};
|
||||
} // namespace impl;
|
||||
|
@ -24,12 +24,14 @@ consteval auto Counter(std::size_t arg) requires Injected<TagWithTalue<Tag, I>{}
|
|||
template <
|
||||
typename Tag,
|
||||
typename... Ts,
|
||||
std::size_t R = impl::Counter<0, Tag, Ts...>(std::size_t{}) - 1
|
||||
std::size_t R = impl::Counter<0, Tag, Ts...>(std::size_t{})
|
||||
#if defined __clang__
|
||||
- 1
|
||||
#endif
|
||||
>
|
||||
consteval auto Counter(auto...) -> std::size_t {
|
||||
return R;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace utempl::loopholes
|
||||
|
|
Loading…
Reference in a new issue