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 a std::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 Types

using DelegateType = Delegate<void(Args...)>

The Delegate type that is referenced.

Public Functions

inline constexpr DelegateRef() noexcept

Default constructor.

Creates an empty DelegateRef such that bool(*this) would be false.

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. If other 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. If other 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. If other 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 be false.

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 if bool(*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.