#ifndef KGR_KANGARU_INCLUDE_KANGARU_OPERATOR_SERVICE_HPP #define KGR_KANGARU_INCLUDE_KANGARU_OPERATOR_SERVICE_HPP #include "container.hpp" #include "operator.hpp" namespace kgr { template struct FilteredForkService { explicit FilteredForkService(in_place_t, Container& container) : _container{container.fork()} {} inline Container forward() { return std::move(_container); } static auto construct(Inject cs) -> decltype(inject(cs.forward())) { return inject(cs.forward()); } private: Container _container; }; using ForkService = FilteredForkService; auto service_map(Container&&) -> ForkService; template class Map> struct InvokerService { explicit InvokerService(in_place_t, Container& container) : _container{container} {} Invoker forward() { return Invoker{_container}; } static auto construct(Inject cs) -> decltype(inject(cs.forward())) { return inject(cs.forward()); } private: Container& _container; }; using DefaultInvokerService = InvokerService; template class Map> auto service_map(const Invoker&) -> InvokerService; template class Map, typename Predicate = All> struct ForkedInvokerService { explicit ForkedInvokerService(in_place_t, Container& container) : _container{container.fork()} {} ForkedInvoker forward() { return ForkedInvoker{std::move(_container)}; } static auto construct(Inject cs) -> decltype(inject(cs.forward())) { return inject(cs.forward()); } private: Container _container; }; using DefaultForkedInvokerService = ForkedInvokerService; template class Map> auto service_map(const ForkedInvoker&) -> ForkedInvokerService; template struct GeneratorService { explicit GeneratorService(in_place_t, Container& container) : _container{container} {} Generator forward() { return Generator{_container}; } static auto construct(Inject cs) -> decltype(inject(cs.forward())) { return inject(cs.forward()); } private: Container& _container; }; template auto service_map(const Generator&) -> GeneratorService; template struct ForkedGeneratorService { explicit ForkedGeneratorService(in_place_t, Container& container) : _container{container.fork()} {} ForkedGenerator forward() { return ForkedGenerator{std::move(_container)}; } static auto construct(Inject cs) -> decltype(inject(cs.forward())) { return inject(cs.forward()); } private: Container _container; }; template auto service_map(const ForkedGenerator&) -> ForkedGeneratorService; template struct LazyService { explicit LazyService(in_place_t, Container& container) : _container{container} {} Lazy forward() { return Lazy{_container}; } static auto construct(Inject cs) -> decltype(inject(cs.forward())) { return inject(cs.forward()); } private: Container& _container; }; template auto service_map(const Lazy&) -> LazyService; template struct ForkedLazyService { explicit ForkedLazyService(in_place_t, Container& container) : _container{container.fork()} {} ForkedLazy forward() { return ForkedLazy{std::move(_container)}; } static auto construct(Inject cs) -> decltype(inject(cs.forward())) { return inject(cs.forward()); } private: Container _container; }; template auto service_map(const ForkedLazy&) -> ForkedLazyService; } // namespace kgr #endif // KGR_KANGARU_INCLUDE_KANGARU_OPERATOR_SERVICE_HPP