template<typename Type, typename Deleter = default_delete<Type>>
bn::unique_ptr class

std::unique_ptr like container.

Template parameters
Type Type of the managed object.
Deleter Type of the object which disposes the managed object when the unique_ptr goes out of scope.

It doesn't throw exceptions. Instead, asserts are used to ensure valid usage.

Unlike most Butano containers, it uses the heap instead of the stack.

Public types

using pointer = Type*
Pointer to the managed object type alias.
using reference = Type&
Reference to the managed object type alias.
using element_type = Type
Managed object type alias.
using deleter_type = Deleter
Deleter type alias.

Constructors, destructors, conversion operators

unique_ptr(nullptr_t) constexpr
Nullptr constructor.
unique_ptr(pointer ptr) explicit constexpr
Constructor.
unique_ptr(unique_ptr&& other) constexpr noexcept
Move constructor.
template<typename OtherType, typename OtherDeleter>
unique_ptr(unique_ptr<OtherType, OtherDeleter>&& other) constexpr
Move constructor.
~unique_ptr() constexpr
Class destructor, which disposes the managed object.
operator bool() const constexpr
Indicates if it contains a managed object or not.

Public functions

auto operator=(unique_ptr&& other) -> unique_ptr& constexpr noexcept
Move assignment operator.
template<typename OtherType, typename OtherDeleter>
auto operator=(unique_ptr<OtherType, OtherDeleter>&& other) -> unique_ptr& constexpr
Move assignment operator.
auto operator=(nullptr_t) -> unique_ptr& constexpr noexcept
Effectively the same as calling reset().
auto get() const -> const Type* constexpr
Returns a const pointer to the managed object.
auto get() -> pointer constexpr
Returns a pointer to the managed object.
auto get_deleter() const -> const Deleter& constexpr
Returns a const reference to the managed object deleter.
auto get_deleter() -> Deleter& constexpr
Returns a reference to the managed object deleter.
auto operator*() const -> const Type& constexpr
Returns a const reference to the managed object.
auto operator*() -> reference constexpr
Returns a reference to the managed object.
auto operator->() const -> const Type* constexpr
Returns a const pointer to the managed object.
auto operator->() -> pointer constexpr
Returns a pointer to the managed object.
auto release() -> pointer constexpr
Releases the ownership of the managed object.
void reset() constexpr
Disposes the managed object.
void reset(pointer ptr) constexpr
Disposes the managed object and replaces it with the given one.
template<typename OtherType>
void reset(OtherType* ptr) constexpr
Disposes the managed object and replaces it with the given one.
void reset(nullptr_t) constexpr
Disposes the managed object.
void swap(unique_ptr& other) constexpr
Exchanges the contents of this unique_ptr with those of the other one.

Friends

void swap(unique_ptr& a, unique_ptr& b) constexpr
Exchanges the contents of a unique_ptr with those of another one.
auto operator==(const unique_ptr& a, const unique_ptr& b) -> bool constexpr
Equal operator.
auto operator!=(const unique_ptr& a, const unique_ptr& b) -> bool constexpr
Not equal operator.
auto operator<(const unique_ptr& a, const unique_ptr& b) -> bool constexpr
Less than operator.
auto operator>(const unique_ptr& a, const unique_ptr& b) -> bool constexpr
Greater than operator.
auto operator<=(const unique_ptr& a, const unique_ptr& b) -> bool constexpr
Less than or equal operator.
auto operator>=(const unique_ptr& a, const unique_ptr& b) -> bool constexpr
Greater than or equal operator.
auto operator==(const unique_ptr& a, nullptr_t b) -> bool constexpr
Equal operator.
auto operator!=(const unique_ptr& a, nullptr_t b) -> bool constexpr
Not equal operator.
auto operator<(const unique_ptr& a, nullptr_t b) -> bool constexpr
Less than operator.
auto operator>(const unique_ptr& a, nullptr_t b) -> bool constexpr
Greater than operator.
auto operator<=(const unique_ptr& a, nullptr_t b) -> bool constexpr
Less than or equal operator.
auto operator>=(const unique_ptr& a, nullptr_t b) -> bool constexpr
Greater than or equal than operator.

Function documentation

template<typename Type, typename Deleter>
bn::unique_ptr<Type, Deleter>::unique_ptr(pointer ptr) explicit constexpr

Constructor.

Parameters
ptr Pointer to the object to manage.

template<typename Type, typename Deleter>
bn::unique_ptr<Type, Deleter>::unique_ptr(unique_ptr&& other) constexpr noexcept

Move constructor.

Parameters
other unique_ptr object to move.

template<typename Type, typename Deleter> template<typename OtherType, typename OtherDeleter>
bn::unique_ptr<Type, Deleter>::unique_ptr(unique_ptr<OtherType, OtherDeleter>&& other) constexpr

Move constructor.

Parameters
other unique_ptr object to move with different type and deleter.

template<typename Type, typename Deleter>
unique_ptr& bn::unique_ptr<Type, Deleter>::operator=(unique_ptr&& other) constexpr noexcept

Move assignment operator.

Parameters
other unique_ptr object to move.
Returns Reference to this.

template<typename Type, typename Deleter> template<typename OtherType, typename OtherDeleter>
unique_ptr& bn::unique_ptr<Type, Deleter>::operator=(unique_ptr<OtherType, OtherDeleter>&& other) constexpr

Move assignment operator.

Parameters
other unique_ptr object to move with different type and deleter.
Returns Reference to this.

template<typename Type, typename Deleter>
pointer bn::unique_ptr<Type, Deleter>::release() constexpr

Releases the ownership of the managed object.

Returns Pointer to the released object.

template<typename Type, typename Deleter>
void bn::unique_ptr<Type, Deleter>::reset(pointer ptr) constexpr

Disposes the managed object and replaces it with the given one.

Parameters
ptr Pointer to the new object to manage.

template<typename Type, typename Deleter> template<typename OtherType>
void bn::unique_ptr<Type, Deleter>::reset(OtherType* ptr) constexpr

Disposes the managed object and replaces it with the given one.

Parameters
ptr Pointer to the new object to manage with different type.

template<typename Type, typename Deleter>
void bn::unique_ptr<Type, Deleter>::swap(unique_ptr& other) constexpr

Exchanges the contents of this unique_ptr with those of the other one.

Parameters
other unique_ptr to exchange the contents with.

template<typename Type, typename Deleter>
void swap(unique_ptr& a, unique_ptr& b) constexpr

Exchanges the contents of a unique_ptr with those of another one.

Parameters
a First unique_ptr to exchange the contents with.
b Second unique_ptr to exchange the contents with.

template<typename Type, typename Deleter>
bool operator==(const unique_ptr& a, const unique_ptr& b) constexpr

Equal operator.

Parameters
a First unique_ptr to compare.
b Second unique_ptr to compare.
Returns true if the first managed object is equal to the second one, otherwise false.

template<typename Type, typename Deleter>
bool operator!=(const unique_ptr& a, const unique_ptr& b) constexpr

Not equal operator.

Parameters
a First unique_ptr to compare.
b Second unique_ptr to compare.
Returns true if the first managed object is not equal to the second one, otherwise false.

template<typename Type, typename Deleter>
bool operator<(const unique_ptr& a, const unique_ptr& b) constexpr

Less than operator.

Parameters
a First unique_ptr to compare.
b Second unique_ptr to compare.
Returns true if the first managed object is lexicographically less than the second one, otherwise false.

template<typename Type, typename Deleter>
bool operator>(const unique_ptr& a, const unique_ptr& b) constexpr

Greater than operator.

Parameters
a First unique_ptr to compare.
b Second unique_ptr to compare.
Returns true if the first managed object is lexicographically greater than the second one, otherwise false.

template<typename Type, typename Deleter>
bool operator<=(const unique_ptr& a, const unique_ptr& b) constexpr

Less than or equal operator.

Parameters
a First unique_ptr to compare.
b Second unique_ptr to compare.
Returns true if the first managed object is lexicographically less than or equal to the second one, otherwise false.

template<typename Type, typename Deleter>
bool operator>=(const unique_ptr& a, const unique_ptr& b) constexpr

Greater than or equal operator.

Parameters
a First unique_ptr to compare.
b Second unique_ptr to compare.
Returns true if the first managed object is lexicographically greater than or equal to the second one, otherwise false.

template<typename Type, typename Deleter>
bool operator==(const unique_ptr& a, nullptr_t b) constexpr

Equal operator.

Parameters
a unique_ptr to compare.
b Null pointer to compare.
Returns true if the unique_ptr does not have a managed object, otherwise false.

template<typename Type, typename Deleter>
bool operator!=(const unique_ptr& a, nullptr_t b) constexpr

Not equal operator.

Parameters
a unique_ptr to compare.
b Null pointer to compare.
Returns true if the unique_ptr has a managed object, otherwise false.

template<typename Type, typename Deleter>
bool operator<(const unique_ptr& a, nullptr_t b) constexpr

Less than operator.

Parameters
a unique_ptr to compare.
b Null pointer to compare.
Returns false.

template<typename Type, typename Deleter>
bool operator>(const unique_ptr& a, nullptr_t b) constexpr

Greater than operator.

Parameters
a unique_ptr to compare.
b Null pointer to compare.
Returns true if the unique_ptr has a managed object, otherwise false.

template<typename Type, typename Deleter>
bool operator<=(const unique_ptr& a, nullptr_t b) constexpr

Less than or equal operator.

Parameters
a unique_ptr to compare.
b Null pointer to compare.
Returns true if the unique_ptr does not have a managed object, otherwise false.

template<typename Type, typename Deleter>
bool operator>=(const unique_ptr& a, nullptr_t b) constexpr

Greater than or equal than operator.

Parameters
a unique_ptr to compare.
b Null pointer to compare.
Returns true.