#pragma once #include "DI/allocation.hpp" #include "DI/compressed_pair.hpp" #include #include #include template struct InvokeReturnWrapper { template static auto call(Args &&...args) -> Return; }; /** * Holds a functor and a allocator. */ template class AllocFunctor; template class AllocFunctor { public: using Target = Function; using Alloc = Allocator; explicit AllocFunctor(Target &&function); explicit AllocFunctor(const Target &function, const Alloc &allocator); explicit AllocFunctor(const Target &function, Alloc &&allocator); explicit AllocFunctor(Target &&function, Alloc &&allocator); auto operator()(Args &&...args) -> Return; [[nodiscard]] auto target() const -> const Target &; [[nodiscard]] auto get_allocator() const -> const Alloc &; [[nodiscard]] auto clone() const -> AllocFunctor *; void destroy() noexcept; static void destroy_and_delete(AllocFunctor *functor); private: CompressedPair _function; }; /** * Holds a functor and a allocator. */ template class DefaultAllocFunctor; template class DefaultAllocFunctor { public: using Target = Function; explicit DefaultAllocFunctor(Target &&function); explicit DefaultAllocFunctor(const Target &function); auto operator()(Args &&...args) -> Return; auto target() const -> const Target &; auto clone() const -> DefaultAllocFunctor *; void destroy() noexcept; static void destroy_and_delete(DefaultAllocFunctor *function); private: Function _function; }; #include "alloc_functor.tpp"