14 template <
typename TResult,
typename... Args>
17 virtual TResult
Invoke(Args... args) = 0;
22 template <
typename F,
typename TResult,
typename... Args>
28 TResult
Invoke(Args... args)
override {
41 template<
typename TResult,
typename... Args>
49 template<
typename TResult>
53 Func() : m_pHolder(nullptr) {}
56 Func(
decltype(
nullptr)) : m_pHolder(nullptr) {}
61 template<
typename F,
typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, Func> && std::is_invocable_r_v<TResult, std::decay_t<F>>>>
62 Func(F&& func) : m_pHolder(new
Internal::FunctorHolder<std::decay_t<F>, TResult>(static_cast<F&&>(func))) {}
66 Func(
const Func& other) : m_pHolder(other.m_pHolder ? other.m_pHolder->Clone() : nullptr) {}
70 Func(
Func&& other) noexcept : m_pHolder(other.m_pHolder) {
71 other.m_pHolder =
nullptr;
80 m_pHolder = other.m_pHolder ? other.m_pHolder->Clone() :
nullptr;
91 m_pHolder = other.m_pHolder;
92 other.m_pHolder =
nullptr;
106 if (m_pHolder)
return m_pHolder->Invoke();
118 explicit operator bool()
const {
return m_pHolder !=
nullptr; }
132 template<
typename TResult,
typename Arg1,
typename... Args>
133 class Func<TResult, Arg1, Args...> {
139 Func(
decltype(
nullptr)) : m_pHolder(nullptr) {}
144 template<
typename F,
typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, Func> && std::is_invocable_r_v<TResult, std::decay_t<F>, Arg1, Args...>>>
145 Func(F&& func) : m_pHolder(new
Internal::FunctorHolder<std::decay_t<F>, TResult, Arg1, Args...>(static_cast<F&&>(func))) {}
149 Func(
const Func& other) : m_pHolder(other.m_pHolder ? other.m_pHolder->Clone() : nullptr) {}
153 Func(
Func&& other) noexcept : m_pHolder(other.m_pHolder) {
154 other.m_pHolder =
nullptr;
161 if (
this != &other) {
163 m_pHolder = other.m_pHolder ? other.m_pHolder->Clone() :
nullptr;
172 if (
this != &other) {
174 m_pHolder = other.m_pHolder;
175 other.m_pHolder =
nullptr;
190 TResult
Invoke(Arg1 arg1, Args... args)
const {
191 if (m_pHolder)
return m_pHolder->Invoke(arg1, args...);
200 return Invoke(arg1, args...);
205 explicit operator bool()
const {
return m_pHolder !=
nullptr; }
TResult operator()(Arg1 arg1, Args... args) const
Function call operator forwarding to Invoke().
Func & operator=(const Func &other)
Copy assignment operator.
TResult Invoke(Arg1 arg1, Args... args) const
Invokes the encapsulated method with specified parameters and returns the result.
Func(F &&func)
Constructs a Func delegate from an invocable callable object or lambda.
Func & operator=(Func &&other) noexcept
Move assignment operator.
Func(decltype(nullptr))
Initializes an empty instance from a null pointer.
~Func()
Destructor releasing functor resources.
Func()
Initializes an empty instance of the parameterized Func delegate.
Func(const Func &other)
Copy constructor.
Func(Func &&other) noexcept
Move constructor.
Func()
Initializes an empty instance of the Func delegate.
Func(F &&func)
Constructs a Func delegate from an invocable callable object or lambda.
~Func()
Destructor releasing functor resources.
Func & operator=(const Func &other)
Copy assignment operator.
TResult operator()() const
Function call operator forwarding to Invoke().
Func(const Func &other)
Copy constructor.
Func & operator=(Func &&other) noexcept
Move assignment operator.
TResult Invoke() const
Invokes the encapsulated method and returns the result.
Func(decltype(nullptr))
Initializes an empty instance from a null pointer.
Func(Func &&other) noexcept
Move constructor.
Primary template declaration for the Func delegate family.
TResult Invoke(Args... args) override
IFunctorHolder< TResult, Args... > * Clone() const override
FunctorHolder(const F &fn)
Internal interface defining type-erased functor execution and cloning.
virtual TResult Invoke(Args... args)=0
virtual ~IFunctorHolder()=default
virtual IFunctorHolder * Clone() const =0