carb::tasking::DelegateRef< void(Args…)>
Defined in carb/tasking/Delegate.h
-
template<class ...Args>
class DelegateRef<void(Args...)> Holds a reference to a Delegate.
Though Delegate is non-copyable,
DelegateRef
can be thought of as astd::shared_ptr
for Delegate. This allows a Delegate’s bindings to remain active even though the original Delegate has been destroyed, which can allow calls in progress to complete, or a mutex protecting the original Delegate to be unlocked.Public Functions
-
inline constexpr DelegateRef() noexcept
Default constructor.
Creates an empty DelegateRef such that
bool(*this)
would befalse
.
-
inline explicit DelegateRef(DelegateType &delegate)
Constructor.
Constructs a DelegateRef that holds a strong reference to
delegate
.- Parameters
delegate – The Delegate object to hold a reference to.
-
inline DelegateRef(const DelegateRef &other)
Copy constructor.
References the same underlying Delegate that
other
references. Ifother
is empty,*this
will also be empty.- Parameters
other – A DelegateRef to copy.
-
DelegateRef(DelegateRef &&other) = default
Move constructor.
Moves the reference from
other
to*this
. Ifother
is empty,*this
will also be empty.other
is left in a valid but empty state.- Parameters
other – A DelegateRef to move.
-
inline ~DelegateRef()
Destructor.
-
inline DelegateRef &operator=(const DelegateRef &other)
Copy-assign.
References the same underlying Delegate that
other
references and releases any existing reference. The order of these operations is unspecified, so assignment from*this
is undefined behavior.- Parameters
other – A DelegateRef to copy.
- Returns
*this
.
-
DelegateRef &operator=(DelegateRef &&other) = default
Move-assign.
Moves the reference from
other
to*this
and releases any existing reference. The order of these operations is unspecified, so assignment from*this
is undefined behavior. Ifother
is empty,*this
will also be empty.other
is left in a valid but empty state.- Parameters
other – A DelegateRef to move.
- Returns
*this
.
-
inline explicit operator bool() const noexcept
Checks whether the DelegateRef holds a valid reference.
- Returns
true
if*this
holds a valid reference;false
otherwise.
-
inline void reset()
Clears the DelegateRef to an empty reference.
Postcondition:
bool(*this)
will befalse
.
-
inline void reset(DelegateType &delegate)
References a different Delegate and releases any existing reference.
- Parameters
delegate – The Delegate to reference.
-
inline void swap(DelegateRef &other)
Swaps the reference with another DelegateRef.
- Parameters
other – A DelegateRef to swap with.
-
inline DelegateType *get() const noexcept
Retrieves the underlying DelegateType.
- Returns
a pointer to the referenced Delegate, or
nullptr
ifbool(*this)
would return false.
-
inline DelegateType &operator*() const noexcept
Dereferences *this.
- Returns
a reference to the referenced Delegate. If
bool(*this)
would return false, behavior is undefined.
-
inline DelegateType *operator->() const noexcept
Dereferences *this.
- Returns
a pointer to the referenced Delegate. If
bool(*this)
would return false, behavior is undefined.
-
inline constexpr DelegateRef() noexcept