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{}>{})}; }; }; };