From 318ae061ba01ecc552df6903fa6e6adfc0854f5f Mon Sep 17 00:00:00 2001 From: sha512sum Date: Sat, 6 Apr 2024 19:49:50 +0000 Subject: [PATCH] Revert "Use utempl counter and injector instead custom realisation" This reverts commit f98f8484d06ad0707a84c3263deb17af35ecfd7c. --- include/cserver/engine/components.hpp | 61 +++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index 43876b4..027ac50 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include #include namespace cserver { @@ -100,6 +99,49 @@ 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 {}; @@ -134,8 +176,8 @@ public: template < utempl::ConstexprString name, typename..., - std::size_t I = utempl::loopholes::Counter>(), - auto = utempl::loopholes::Injector< + std::size_t I = loopholes::Counter>(), + auto = loopholes::Injector< DependencyInfoKey< Current, I @@ -144,11 +186,12 @@ public: >{} > static constexpr auto FindComponent() -> FindComponentType&; + template < typename T, typename..., - std::size_t I = utempl::loopholes::Counter>>(), - auto = utempl::loopholes::Injector< + std::size_t I = loopholes::Counter>>(), + auto = loopholes::Injector< DependencyInfoKey< Current, I @@ -160,14 +203,14 @@ public: template static consteval auto GetDependencies() requires (I == 0 || - requires {Magic(utempl::loopholes::Getter{}>{});}) { - if constexpr(I == 0 && !requires {Magic(utempl::loopholes::Getter{}>{});}) { + requires {Magic(loopholes::Getter{}>{});}) { + if constexpr(I == 0 && !requires {Magic(loopholes::Getter{}>{});}) { return utempl::Tuple{}; } else { if constexpr(requires{GetDependencies();}) { - return GetDependencies{}>{})>(); + return GetDependencies{}>{})>(); } else { - return utempl::Tuple{names..., Magic(utempl::loopholes::Getter{}>{})}; + return utempl::Tuple{names..., Magic(loopholes::Getter{}>{})}; }; }; };