Use utempl loopholes impl instead custom

This commit is contained in:
sha512sum 2024-06-27 01:07:32 +00:00
parent 327bc969b8
commit 0d77aa7e3c

View file

@ -2,6 +2,7 @@
#include <cserver/engine/basic/task_processor.hpp> #include <cserver/engine/basic/task_processor.hpp>
#include <cserver/engine/coroutine.hpp> #include <cserver/engine/coroutine.hpp>
#include <utempl/utils.hpp> #include <utempl/utils.hpp>
#include <utempl/loopholes/counter.hpp>
namespace cserver { namespace cserver {
@ -176,48 +177,6 @@ struct ServiceContext {
namespace impl { namespace impl {
namespace loopholes {
template <auto I>
struct Getter {
friend constexpr auto Magic(Getter<I>);
};
template <auto I, auto Value = 0>
struct Injector {
friend constexpr auto Magic(Getter<I>) {return Value;};
};
template <auto I, typename...>
concept Injected = requires{Magic(Getter<I>{});};
template <typename Tag, auto Value>
struct TagWithTalue {};
template <auto I = 0, typename Tag, typename... Ts, auto = Injector<TagWithTalue<Tag, I>{}>{}>
constexpr auto CounterImpl(...) {
return I;
};
template <auto I = 0, typename Tag, typename... Ts>
consteval auto CounterImpl(std::size_t arg) requires Injected<TagWithTalue<Tag, I>{}, Ts...> {
return CounterImpl<I + 1, Tag, Ts...>(arg);
};
template <
typename Tag,
typename... Ts,
auto R = CounterImpl<0, Tag, Ts...>(std::size_t{})
>
consteval auto Counter(auto...) {
return R;
};
} // namespace loopholes
template <typename Current, std::size_t I> template <typename Current, std::size_t I>
struct DependencyInfoKey {}; struct DependencyInfoKey {};
@ -257,8 +216,8 @@ public:
template < template <
utempl::ConstexprString name, utempl::ConstexprString name,
typename..., typename...,
std::size_t I = loopholes::Counter<Current, utempl::Wrapper<name>>(), std::size_t I = utempl::loopholes::Counter<Current, utempl::Wrapper<name>>(),
auto = loopholes::Injector< auto = utempl::loopholes::Injector<
DependencyInfoKey< DependencyInfoKey<
Current, Current,
I I
@ -272,8 +231,8 @@ public:
template < template <
typename T, typename T,
typename..., typename...,
std::size_t I = loopholes::Counter<Current, utempl::Wrapper<FindComponentName<T>>>(), std::size_t I = utempl::loopholes::Counter<Current, utempl::Wrapper<FindComponentName<T>>>(),
auto = loopholes::Injector< auto = utempl::loopholes::Injector<
DependencyInfoKey< DependencyInfoKey<
Current, Current,
I I
@ -282,31 +241,20 @@ public:
>{} >{}
> >
static constexpr auto FindComponent() -> T&; static constexpr auto FindComponent() -> T&;
template <std::size_t I = 0, utempl::ConstexprString... names> template <auto = 0>
static consteval auto GetDependencies() requires (I == 0 || static consteval auto GetDependencies() {
requires {Magic(loopholes::Getter<DependencyInfoKey<Current, I>{}>{});}) { return [](auto... is) {
if constexpr(I == 0 && !requires {Magic(loopholes::Getter<DependencyInfoKey<Current, I>{}>{});}) { return ([&]{
return utempl::Tuple{}; constexpr auto response = Magic(utempl::loopholes::Getter<DependencyInfoKey<Current, is>{}>{});
} else { if constexpr(response == kBasicTaskProcessorName) {
if constexpr(requires{GetDependencies<I + 1, names...>();}) { return utempl::Tuple{};
constexpr auto name = Magic(loopholes::Getter<DependencyInfoKey<Current, I>{}>{});
if constexpr(name == kBasicTaskProcessorName) {
return GetDependencies<I + 1, names...>();
} else { } else {
return GetDependencies<I + 1, names..., name>(); return utempl::Tuple{response};
}; };
} else { }() + ... + utempl::Tuple{});
constexpr auto name = Magic(loopholes::Getter<DependencyInfoKey<Current, I>{}>{}); } | utempl::kSeq<utempl::loopholes::Counter<Current>()>;
if constexpr(static_cast<std::string_view>(name) == kBasicTaskProcessorName) {
return utempl::Tuple{names...};
} else {
return utempl::Tuple{names..., name};
};
};
};
}; };
template <utempl::ConstexprString name> template <utempl::ConstexprString name>
static inline consteval auto Inject() { static inline consteval auto Inject() {
Ignore<decltype(Use<Current, utempl::Wrapper<name>{}, DependencyInfoInjector<Current, config, Ts...>{}>())>(); Ignore<decltype(Use<Current, utempl::Wrapper<name>{}, DependencyInfoInjector<Current, config, Ts...>{}>())>();