#include <bn_memory.h>
template<typename Type, typename Deleter = default_delete<Type>>
bn::unique_ptr class

std::shared_ptr like smart pointer that owns and manages another object through a pointer and disposes of that object when the unique_ptr goes out of scope.

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.

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(pointer ptr) explicit
Constructor.
unique_ptr(unique_ptr&& other) noexcept
Move constructor.
~unique_ptr()
Class destructor, which disposes the managed object.
operator bool() const
Indicates if it contains a managed object or not.

Public functions

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

Friends

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

Function documentation

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

Constructor.

Parameters
ptr Pointer to the object to manage.

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

Move constructor.

Parameters
other unique_ptr object to move.

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

Move assignment operator.

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

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

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)

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>
void bn::unique_ptr<Type, Deleter>::swap(unique_ptr& other)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

Greater than or equal than operator.

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