diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index 2ea93f8..d667b21 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace cserver { @@ -176,48 +177,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 {}; @@ -257,8 +216,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 @@ -272,8 +231,8 @@ public: 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 @@ -282,31 +241,20 @@ public: >{} > static constexpr auto FindComponent() -> T&; - - template - static consteval auto GetDependencies() requires (I == 0 || - requires {Magic(loopholes::Getter{}>{});}) { - if constexpr(I == 0 && !requires {Magic(loopholes::Getter{}>{});}) { - return utempl::Tuple{}; - } else { - if constexpr(requires{GetDependencies();}) { - constexpr auto name = Magic(loopholes::Getter{}>{}); - if constexpr(name == kBasicTaskProcessorName) { - return GetDependencies(); + + template + static consteval auto GetDependencies() { + return [](auto... is) { + return ([&]{ + constexpr auto response = Magic(utempl::loopholes::Getter{}>{}); + if constexpr(response == kBasicTaskProcessorName) { + return utempl::Tuple{}; } else { - return GetDependencies(); + return utempl::Tuple{response}; }; - } else { - constexpr auto name = Magic(loopholes::Getter{}>{}); - if constexpr(static_cast(name) == kBasicTaskProcessorName) { - return utempl::Tuple{names...}; - } else { - return utempl::Tuple{names..., name}; - }; - }; - }; + }() + ... + utempl::Tuple{}); + } | utempl::kSeq()>; }; - template static inline consteval auto Inject() { Ignore{}, DependencyInfoInjector{}>())>();