From 475d310f6710eaecca5138ffafffd43ca13d9728 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Fri, 28 Jun 2024 14:01:49 +0000 Subject: [PATCH] Add CountValue --- include/utempl/loopholes/counter.hpp | 33 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/include/utempl/loopholes/counter.hpp b/include/utempl/loopholes/counter.hpp index eab2e0e..c765452 100644 --- a/include/utempl/loopholes/counter.hpp +++ b/include/utempl/loopholes/counter.hpp @@ -10,24 +10,49 @@ namespace impl { template struct TagWithValue {}; -template +template consteval auto Counter() -> std::size_t { if constexpr(requires{Magic(Getter{}>{});}) { - return Counter(); + return Counter(); + }; + if constexpr(Add) { + return (std::ignore = Injector{}, 0>{}, I); + } else { + return I; }; - return (std::ignore = Injector{}, 0>{}, I); }; + + } // namespace impl; // For incerement counter need a unique Ts... template < typename Tag, typename... Ts, - std::size_t R = impl::Counter() + std::size_t R = impl::Counter() > consteval auto Counter(auto...) -> std::size_t { return R; }; + +// Without increment +template < + typename Tag, + typename... Ts, + std::size_t R = impl::Counter() +> +consteval auto CountValue(auto...) -> std::size_t { + return R; +}; + + +/* +static_assert(Counter() == 0); +static_assert(Counter() == 1); +static_assert(CountValue() == 2); +static_assert(CountValue() == 2); +*/ + } // namespace utempl::loopholes