#include <bn_unique_ptr.h>
template<typename Type, typename Deleter = default_ delete<Type>>
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_ |
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_ |
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_ |
template<typename Type, typename Deleter>
unique_ ptr& bn:: unique_ptr<Type, Deleter>:: operator=(unique_ ptr&& other) constexpr noexcept
Move assignment operator.
Parameters | |
---|---|
other | unique_ |
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_ |
Returns | Reference to this. |
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_
Parameters | |
---|---|
other | unique_ |
template<typename Type, typename Deleter>
void swap(unique_ ptr& a,
unique_ ptr& b) constexpr
Exchanges the contents of a unique_
Parameters | |
---|---|
a | First unique_ |
b | Second unique_ |
template<typename Type, typename Deleter>
bool operator==(const unique_ ptr& a,
const unique_ ptr& b) constexpr
Equal operator.
Parameters | |
---|---|
a | First unique_ |
b | Second unique_ |
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_ |
b | Second unique_ |
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_ |
b | Second unique_ |
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_ |
b | Second unique_ |
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_ |
b | Second unique_ |
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_ |
b | Second unique_ |
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_ |
b | Null pointer to compare. |
Returns | true if the unique_false . |
template<typename Type, typename Deleter>
bool operator!=(const unique_ ptr& a,
nullptr_t b) constexpr
Not equal operator.
Parameters | |
---|---|
a | unique_ |
b | Null pointer to compare. |
Returns | true if the unique_false . |
template<typename Type, typename Deleter>
bool operator<(const unique_ ptr& a,
nullptr_t b) constexpr
Less than operator.
Parameters | |
---|---|
a | unique_ |
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_ |
b | Null pointer to compare. |
Returns | true if the unique_false . |
template<typename Type, typename Deleter>
bool operator<=(const unique_ ptr& a,
nullptr_t b) constexpr
Less than or equal operator.
Parameters | |
---|---|
a | unique_ |
b | Null pointer to compare. |
Returns | true if the unique_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_ |
b | Null pointer to compare. |
Returns | true . |