From f98f8484d06ad0707a84c3263deb17af35ecfd7c Mon Sep 17 00:00:00 2001 From: sha512sum Date: Wed, 27 Mar 2024 23:50:08 +0000 Subject: [PATCH] Use utempl counter and injector instead custom realisation --- include/cserver/engine/components.hpp | 61 ++++----------------------- 1 file changed, 9 insertions(+), 52 deletions(-) diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index 5c7b43c..3454218 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include namespace cserver { @@ -99,49 +100,6 @@ struct ServiceContext { namespace impl { -namespace loopholes { - -template -struct Getter { - friend constexpr auto Magic(Getter); -}; -template -struct Injector { - friend constexpr auto Magic(Getter) {return Value;}; -}; - - -template -concept Injected = requires{Magic(Getter{});}; - -template -struct TagWithTalue {}; - - -template {}>{}> -constexpr auto CounterImpl(...) { - return I; -}; - -template -consteval auto CounterImpl(std::size_t arg) requires Injected{}, Ts...> { - return CounterImpl(arg); -}; - - -template < - typename Tag, - typename... Ts, - auto R = CounterImpl<0, Tag, Ts...>(std::size_t{}) -> -consteval auto Counter(auto...) { - return R; -}; - - -} // namespace loopholes - - template struct DependencyInfoKey {}; @@ -176,8 +134,8 @@ public: template < utempl::ConstexprString name, typename..., - std::size_t I = loopholes::Counter>(), - auto = loopholes::Injector< + std::size_t I = utempl::loopholes::Counter>(), + auto = utempl::loopholes::Injector< DependencyInfoKey< Current, I @@ -186,12 +144,11 @@ public: >{} > static constexpr auto FindComponent() -> FindComponentType&; - template < typename T, typename..., - std::size_t I = loopholes::Counter>>(), - auto = loopholes::Injector< + std::size_t I = utempl::loopholes::Counter>>(), + auto = utempl::loopholes::Injector< DependencyInfoKey< Current, I @@ -203,14 +160,14 @@ public: template static consteval auto GetDependencies() requires (I == 0 || - requires {Magic(loopholes::Getter{}>{});}) { - if constexpr(I == 0 && !requires {Magic(loopholes::Getter{}>{});}) { + requires {Magic(utempl::loopholes::Getter{}>{});}) { + if constexpr(I == 0 && !requires {Magic(utempl::loopholes::Getter{}>{});}) { return utempl::Tuple{}; } else { if constexpr(requires{GetDependencies();}) { - return GetDependencies{}>{})>(); + return GetDependencies{}>{})>(); } else { - return utempl::Tuple{names..., Magic(loopholes::Getter{}>{})}; + return utempl::Tuple{names..., Magic(utempl::loopholes::Getter{}>{})}; }; }; };