From 94c6f53b4f0fe0646f3cdee98a764c6e5916efef Mon Sep 17 00:00:00 2001 From: sha512sum Date: Mon, 22 Apr 2024 17:10:31 +0000 Subject: [PATCH] Fix counter in gcc --- include/utempl/loopholes/core.hpp | 15 +++++++++++++-- include/utempl/loopholes/counter.hpp | 12 +++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/utempl/loopholes/core.hpp b/include/utempl/loopholes/core.hpp index 953a87c..84a37c8 100644 --- a/include/utempl/loopholes/core.hpp +++ b/include/utempl/loopholes/core.hpp @@ -1,3 +1,4 @@ +#include #pragma once namespace utempl::loopholes { @@ -12,8 +13,18 @@ struct Injector { }; -template -concept Injected = requires{Magic(Getter{});}; +template +struct InjectedImpl { + static constexpr bool value = false; +}; +template +struct InjectedImpl{}))>, Ts...> { + static constexpr bool value = true; +}; + +template +concept Injected = InjectedImpl::value; + diff --git a/include/utempl/loopholes/counter.hpp b/include/utempl/loopholes/counter.hpp index a1ca9f5..dd6a7be 100644 --- a/include/utempl/loopholes/counter.hpp +++ b/include/utempl/loopholes/counter.hpp @@ -7,15 +7,15 @@ namespace utempl::loopholes { namespace impl { template -struct TagWithTalue {}; +struct TagWithValue {}; -template {}>{}> +template {}>{}> constexpr auto Counter(...) { return I; }; template -consteval auto Counter(std::size_t arg) requires Injected{}, Ts...> { +consteval auto Counter(std::size_t arg) requires Injected{}, Ts...> { return Counter(arg); }; } // namespace impl; @@ -24,12 +24,14 @@ consteval auto Counter(std::size_t arg) requires Injected{} 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