Template Class UniqueHandle

Class Documentation

template<typename HandleType, typename HandleOps = detail::UniqueHandleOps<HandleType>>
class UniqueHandle

A handle wrapper that behaves like a unique_ptr.

Template Parameters:
  • HandleType – The type of the managed handle

  • HandleOps – The set of handle operations - can be customized e.g. to add extra tracking or suppress object deletion.

Public Functions

inline ~UniqueHandle()
inline explicit UniqueHandle(HandleType &&handle)

Constructs a UniqueHandle that from a bare handle.

Constructs a UniqueHandle that manages the handles passed in the argument. The ownership of the object is transferred to UniqueHandle and the handle must not be destroyed manually.

Parameters:

handle – The handle to be managed. The handle is passed by an r-value reference and is set to null to emphasize the transfer of ownership.

UniqueHandle() = default
UniqueHandle(const UniqueHandle &other) = delete
inline UniqueHandle(UniqueHandle &&other)
inline UniqueHandle &operator=(UniqueHandle &&other)

Moves the handle owned by other into this object and releases the old handle.

inline void swap(UniqueHandle &other) noexcept

Swaps the handles managed by this and other

inline void reset(HandleType &&handle = HandleOps::Null())

Replaces the managed handle and destroys the previously owned resource, if the handle was not null.

Remark

Passing a non-empty handle that’s already owned by this UniqueHandle is forbidden and will result in double destruction of the handle.

Parameters:

handle – The handle to be managed. The handle is passed by an r-value reference and is set to null to emphasize the transfer of ownership.

inline HandleType release() noexcept

Relinquishes the ownership of the handle and returns the formerly managed handle.

The function returns the handle and stops managing it. The caller is resposnible for destroying the handle.

Returns:

The (formerly) managed handle. The values must not be discarded.

inline constexpr const HandleType get() const noexcept

Returns the managed handle.

Returns:

The managed handle.

inline constexpr bool empty() const noexcept
inline explicit constexpr operator bool() const noexcept
inline bool operator==(const UniqueHandle &other) const
inline bool operator!=(const UniqueHandle &other) const