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