throwing_ptr
Smart pointers that throw on dereference if null
|
unique_ptr that manages a single object More...
Public Types | |
typedef std::unique_ptr< T, Deleter > | std_unique_ptr_type |
type of the wrapped std::unique_ptr. More... | |
typedef std::unique_ptr< T, Deleter >::pointer | pointer |
type of the pointer to the pointed object. More... | |
typedef std::unique_ptr< T, Deleter >::element_type | element_type |
type of the pointed object. More... | |
typedef std::unique_ptr< T, Deleter >::deleter_type | deleter_type |
type of the deleter. More... | |
Public Member Functions | |
TSP_CONSTEXPR | unique_ptr () TSP_NOEXCEPT=default |
Constructs a unique_ptr that owns nothing. More... | |
TSP_CONSTEXPR | unique_ptr (std::nullptr_t) TSP_NOEXCEPT |
Constructs a unique_ptr that owns nothing. More... | |
unique_ptr (pointer ptr) TSP_NOEXCEPT | |
Constructs a unique_ptr which owns p. More... | |
unique_ptr (pointer ptr, typename std::conditional< std::is_reference< Deleter >::value, Deleter, const Deleter &>::type d1) TSP_NOEXCEPT | |
Constructs a std::unique_ptr object which owns p. More... | |
unique_ptr (pointer ptr, typename std::remove_reference< Deleter >::type &&d2) TSP_NOEXCEPT | |
Constructs a std::unique_ptr object which owns p. More... | |
unique_ptr (unique_ptr &&u) TSP_NOEXCEPT | |
Constructs a unique_ptr by transferring ownership from u to *this. More... | |
template<class U , class E > | |
unique_ptr (unique_ptr< U, E > &&u) TSP_NOEXCEPT | |
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a specified deleter (E). More... | |
template<class U , class E > | |
unique_ptr (std::unique_ptr< U, E > &&u) TSP_NOEXCEPT | |
Constructs a unique_ptr by transferring ownership from a std::unique_ptr u to *this, where u is constructed with a specified deleter (E). More... | |
~unique_ptr ()=default | |
Destructor If get() == nullptr there are no effects. Otherwise, the owned object is destroyed via get_deleter()(get()) on the underlying unique_ptr. More... | |
unique_ptr & | operator= (unique_ptr &&r) TSP_NOEXCEPT |
Assignment operator. More... | |
template<class U , class E > | |
unique_ptr & | operator= (unique_ptr< U, E > &&r) TSP_NOEXCEPT |
Assignment operator. More... | |
template<class U , class E > | |
unique_ptr & | operator= (std::unique_ptr< U, E > &&r) TSP_NOEXCEPT |
Assignment from std::unique_ptr operator. More... | |
unique_ptr & | operator= (std::nullptr_t) TSP_NOEXCEPT |
Assignment operator. More... | |
pointer | release () TSP_NOEXCEPT |
Releases the ownership of the managed object if any. More... | |
void | reset (pointer ptr=pointer()) TSP_NOEXCEPT |
Replaces the managed object. More... | |
void | swap (unique_ptr &other) TSP_NOEXCEPT |
Swaps the managed objects and associated deleters of *this and another unique_ptr object other. More... | |
pointer | get () const TSP_NOEXCEPT |
Returns a pointer to the managed object or nullptr if no object is owned. More... | |
Deleter & | get_deleter () TSP_NOEXCEPT |
Returns the deleter object which would be used for destruction of the managed object. More... | |
const Deleter & | get_deleter () const TSP_NOEXCEPT |
Returns the deleter object which would be used for destruction of the managed object. More... | |
operator bool () const TSP_NOEXCEPT | |
Checks whether *this owns an object, i.e. whether get() != nullptr. More... | |
std::add_lvalue_reference< T >::type | operator* () const |
Dereferences the stored pointer. More... | |
pointer | operator-> () const |
Dereferences the stored pointer. More... | |
std_unique_ptr_type & | get_std_unique_ptr () TSP_NOEXCEPT |
Returns reference to the wrapped std::unique_ptr. More... | |
const std_unique_ptr_type & | get_std_unique_ptr () const TSP_NOEXCEPT |
Returns const reference to the wrapped std::unique_ptr. More... | |
Friends | |
template<typename OtherT , typename OtherDeleter > | |
class | unique_ptr |
unique_ptr that manages a single object
throwing::unique_ptr is a smart pointer that owns and manages another object through a pointer and disposes of that object when the unique_ptr goes out of scope.
The object is disposed of using the associated deleter when either of the following happens:
The object is disposed of using a potentially user-supplied deleter by calling get_deleter()(ptr). The default deleter uses the delete operator, which destroys the object and deallocates the memory.
A unique_ptr may alternatively own no object, in which case it is called empty.
Definition at line 38 of file unique_ptr.hpp.
typedef std::unique_ptr<T, Deleter>::deleter_type throwing::unique_ptr< T, Deleter >::deleter_type |
type of the deleter.
Definition at line 47 of file unique_ptr.hpp.
typedef std::unique_ptr<T, Deleter>::element_type throwing::unique_ptr< T, Deleter >::element_type |
type of the pointed object.
Definition at line 45 of file unique_ptr.hpp.
typedef std::unique_ptr<T, Deleter>::pointer throwing::unique_ptr< T, Deleter >::pointer |
type of the pointer to the pointed object.
Definition at line 43 of file unique_ptr.hpp.
typedef std::unique_ptr<T, Deleter> throwing::unique_ptr< T, Deleter >::std_unique_ptr_type |
type of the wrapped std::unique_ptr.
Definition at line 41 of file unique_ptr.hpp.
|
default |
Constructs a unique_ptr that owns nothing.
Value-initializes the stored pointer and the stored deleter. Requires that Deleter is DefaultConstructible and that construction does not throw an exception.
|
inline |
Constructs a unique_ptr that owns nothing.
Value-initializes the stored pointer and the stored deleter. Requires that Deleter is DefaultConstructible and that construction does not throw an exception.
Definition at line 66 of file unique_ptr.hpp.
|
inlineexplicit |
Constructs a unique_ptr which owns p.
Initialises the stored pointer with ptr and value-initialises the stored deleter.
Requires that Deleter is DefaultConstructible and that construction does not throw an exception.
Definition at line 76 of file unique_ptr.hpp.
|
inline |
Constructs a std::unique_ptr object which owns p.
Initialises the stored pointer with ptr and initialises the stored deleter with d1
Requires that Deleter is nothrow-CopyConstructible
Definition at line 87 of file unique_ptr.hpp.
|
inline |
Constructs a std::unique_ptr object which owns p.
Initialises the stored pointer with ptr. Moves d2 into stored_deleter.
Definition at line 97 of file unique_ptr.hpp.
|
inline |
Constructs a unique_ptr by transferring ownership from u to *this.
If Deleter is not a reference type, requires that it is nothrow-MoveConstructible (if Deleter is a reference, get_deleter() and u.get_deleter() after move construction reference the same value)
Definition at line 108 of file unique_ptr.hpp.
|
inline |
Constructs a unique_ptr by transferring ownership from u to *this, where u is constructed with a specified deleter (E).
It depends upon whether E is a reference type, as following: a) if E is a reference type, this deleter is copy constructed from u's deleter (requires that this construction does not throw) b) if E is a non-reference type, this deleter is move constructed from u's deleter (requires that this construction does not throw)
This constructor only participates in overload resolution if all of the following is true: a) unique_ptr<U, E>::pointer is implicitly convertible to pointer b) U is not an array type c) Either Deleter is a reference type and E is the same type as D, or Deleter is not a reference type and E is implicitly convertible to D
Definition at line 127 of file unique_ptr.hpp.
|
inline |
Constructs a unique_ptr by transferring ownership from a std::unique_ptr u to *this, where u is constructed with a specified deleter (E).
It depends upon whether E is a reference type, as following: a) if E is a reference type, this deleter is copy constructed from u's deleter (requires that this construction does not throw) b) if E is a non-reference type, this deleter is move constructed from u's deleter (requires that this construction does not throw)
This constructor only participates in overload resolution if all of the following is true: a) std::unique_ptr<U, E>::pointer is implicitly convertible to pointer b) U is not an array type c) Either Deleter is a reference type and E is the same type as D, or Deleter is not a reference type and E is implicitly convertible to D
Definition at line 148 of file unique_ptr.hpp.
|
default |
Destructor If get() == nullptr there are no effects. Otherwise, the owned object is destroyed via get_deleter()(get()) on the underlying unique_ptr.
Requires that get_deleter()(get()) does not throw exceptions.
|
inline |
Returns a pointer to the managed object or nullptr if no object is owned.
Definition at line 257 of file unique_ptr.hpp.
|
inline |
Returns the deleter object which would be used for destruction of the managed object.
Definition at line 262 of file unique_ptr.hpp.
|
inline |
Returns the deleter object which would be used for destruction of the managed object.
Definition at line 267 of file unique_ptr.hpp.
|
inline |
Returns reference to the wrapped std::unique_ptr.
Definition at line 297 of file unique_ptr.hpp.
|
inline |
Returns const reference to the wrapped std::unique_ptr.
Definition at line 301 of file unique_ptr.hpp.
|
inlineexplicit |
Checks whether *this owns an object, i.e. whether get() != nullptr.
Definition at line 272 of file unique_ptr.hpp.
|
inline |
Dereferences the stored pointer.
null_ptr_exception<T> | if the pointer is null |
Definition at line 278 of file unique_ptr.hpp.
|
inline |
Dereferences the stored pointer.
null_ptr_exception<T> | if the pointer is null |
Definition at line 288 of file unique_ptr.hpp.
|
inline |
Assignment operator.
Transfers ownership from r to *this as if by calling reset(r.release()) followed by an assignment of get_deleter() from std::forward<E>(r.get_deleter()).
If Deleter is not a reference type, requires that it is nothrow-MoveAssignable.
If Deleter is a reference type, requires that std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
Definition at line 170 of file unique_ptr.hpp.
|
inline |
Assignment operator.
Transfers ownership from r to *this as if by calling reset(r.release()) followed by an assignment of get_deleter() from std::forward<E>(r.get_deleter()).
If Deleter is not a reference type, requires that it is nothrow-MoveAssignable.
If Deleter is a reference type, requires that std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
Only participates in overload resolution if U is not an array type and unique_ptr<U,E>::pointer is implicitly convertible to pointer and std::is_assignable<Deleter&, E&&>::value is true (since C++17).
Definition at line 192 of file unique_ptr.hpp.
|
inline |
Assignment from std::unique_ptr operator.
Transfers ownership from a std::unique_ptr r to *this as if by calling reset(r.release()) followed by an assignment of get_deleter() from std::forward<E>(r.get_deleter()).
If Deleter is not a reference type, requires that it is nothrow-MoveAssignable.
If Deleter is a reference type, requires that std::remove_reference<Deleter>::type is nothrow-CopyAssignable.
Only participates in overload resolution if U is not an array type and unique_ptr<U,E>::pointer is implicitly convertible to pointer and std::is_assignable<Deleter&, E&&>::value is true (since C++17).
Definition at line 214 of file unique_ptr.hpp.
|
inline |
Assignment operator.
Effectively the same as calling reset().
Definition at line 223 of file unique_ptr.hpp.
|
inline |
Releases the ownership of the managed object if any.
get() returns nullptr after the call.
Definition at line 235 of file unique_ptr.hpp.
|
inline |
Replaces the managed object.
Given current_ptr, the pointer that was managed by *this, performs the following actions, in this order:
Definition at line 247 of file unique_ptr.hpp.
|
inline |
Swaps the managed objects and associated deleters of *this and another unique_ptr object other.
Definition at line 252 of file unique_ptr.hpp.
|
friend |
Definition at line 50 of file unique_ptr.hpp.