15 template <
typename... Args>
18 virtual void Invoke(Args... args) = 0;
24 template <
typename F,
typename... Args>
45 template<
typename... Args>
57 Action(
decltype(
nullptr)) : m_pHolder(nullptr) {}
62 template<
typename F,
typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, Action> && std::is_invocable_v<std::decay_t<F>>>>
63 Action(F&& func) : m_pHolder(new
Internal::ActionHolder<std::decay_t<F>>(static_cast<F&&>(func))) {}
67 Action(
const Action& other) : m_pHolder(other.m_pHolder ? other.m_pHolder->Clone() : nullptr) {}
72 other.m_pHolder =
nullptr;
79 m_pHolder = other.m_pHolder ? other.m_pHolder->Clone() :
nullptr;
88 m_pHolder = other.m_pHolder;
89 other.m_pHolder =
nullptr;
102 if (m_pHolder) m_pHolder->Invoke();
111 explicit operator bool()
const {
return m_pHolder !=
nullptr; }
119 template<
typename Arg1,
typename... Args>
126 Action(
decltype(
nullptr)) : m_pHolder(nullptr) {}
129 template<
typename F,
typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, Action> && std::is_invocable_v<std::decay_t<F>, Arg1, Args...>>>
130 Action(F&& func) : m_pHolder(new
Internal::ActionHolder<std::decay_t<F>, Arg1, Args...>(static_cast<F&&>(func))) {}
133 Action(
const Action& other) : m_pHolder(other.m_pHolder ? other.m_pHolder->Clone() : nullptr) {}
137 other.m_pHolder =
nullptr;
142 if (
this != &other) {
144 m_pHolder = other.m_pHolder ? other.m_pHolder->Clone() :
nullptr;
151 if (
this != &other) {
153 m_pHolder = other.m_pHolder;
154 other.m_pHolder =
nullptr;
166 void Invoke(Arg1 arg1, Args... args)
const {
167 if (m_pHolder) m_pHolder->Invoke(arg1, args...);
176 explicit operator bool()
const {
return m_pHolder !=
nullptr; }
Action & operator=(const Action &other)
Copy assignment operator.
Action(F &&func)
Constructs an Action wrapping the specified callable object.
Action(const Action &other)
Copy constructor.
Action()
Default constructor.
Action(decltype(nullptr))
Nullptr constructor.
Action & operator=(Action &&other) noexcept
Move assignment operator.
Action(Action &&other) noexcept
Move constructor.
void operator()(Arg1 arg1, Args... args) const
Function call operator executing Invoke.
void Invoke(Arg1 arg1, Args... args) const
Invokes the wrapped action delegate with arguments.
Action & operator=(Action &&other) noexcept
Move assignment operator.
Action(decltype(nullptr))
Constructs an empty Action from nullptr.
~Action()
Destructor releasing target callable holder.
Action(Action &&other) noexcept
Move constructor transferring delegate ownership.
Action()
Default constructor creating an empty unassigned Action.
Action & operator=(const Action &other)
Copy assignment operator.
Action(const Action &other)
Copy constructor performing deep clone of target delegate.
Action(F &&func)
Constructs an Action wrapping the specified callable functor.
void operator()() const
Function call operator executing Invoke.
void Invoke() const
Invokes the wrapped action delegate.
Encapsulates a method that has parameters and does not return a value.
IActionHolder< Args... > * Clone() const override
void Invoke(Args... args) override
ActionHolder(const F &fn)
Type-erased polymorphic interface for invocable action delegates.
virtual void Invoke(Args... args)=0
virtual ~IActionHolder()=default
virtual IActionHolder * Clone() const =0