CsPointer
1.0.1
|
Contains a pointer to an object and takes exclusive ownership. More...
Public Typedefs | |
using | pointer = typename std::unique_ptr< T, Deleter >::pointer |
using | element_type = typename std::unique_ptr< T, Deleter >::element_type |
using | deleter_type = typename std::unique_ptr< T, Deleter >::deleter_type |
using | Pointer = pointer |
using | ElementType = element_type |
using | DeleterType = deleter_type |
Public Member Functions | |
CsUniquePointer (Pointer p=nullptr) noexcept | |
CsUniquePointer (Pointer p, Deleter d) noexcept | |
CsUniquePointer (std::unique_ptr< T, Deleter > &&p) noexcept | |
~CsUniquePointer () = default | |
CsUniquePointer (CsUniquePointer &&other) = default | |
CsUniquePointer & | operator= (CsUniquePointer &&other) = default |
ElementType & | operator* () const noexcept (noexcept (*std::declval< Pointer >())) |
Pointer | operator-> () const noexcept |
bool | operator! () const noexcept |
operator bool () const noexcept | |
operator std::unique_ptr< T, Deleter > () &&noexcept | |
Pointer | data () const noexcept |
Pointer | get () const noexcept |
Deleter & | get_deleter () noexcept |
const Deleter & | get_deleter () const noexcept |
bool | is_null () const noexcept |
Pointer | release () noexcept |
void | reset (Pointer other=nullptr) noexcept |
void | swap (CsUniquePointer &other) noexcept |
Pointer | take () noexcept |
Related Functions | |
These are not member functions | |
CsUniquePointer< T > | make_unique (Args &&...args) |
bool | operator== (const CsUniquePointer< T1, Deleter1 > &ptr1, const CsUniquePointer< T2, Deleter2 > &ptr2) |
bool | operator== (const CsUniquePointer< T1, Deleter1 > &ptr1, const T2 *ptr2) |
bool | operator== (const T1 *ptr1, const CsUniquePointer< T2, Deleter2 > &ptr2) |
bool | operator== (const CsUniquePointer< T, Deleter > &ptr1, std::nullptr_t) |
bool | operator== (std::nullptr_t, const CsUniquePointer< T, Deleter > &ptr2) |
bool | operator!= (const CsUniquePointer< T1, Deleter1 > &ptr1, const CsUniquePointer< T2, Deleter2 > &ptr2) |
bool | operator!= (const CsUniquePointer< T1, Deleter1 > &ptr1, const T2 *ptr2) |
bool | operator!= (const T1 *ptr1, const CsUniquePointer< T2, Deleter2 > &ptr2) |
bool | operator!= (const CsUniquePointer< T, Deleter > &ptr1, std::nullptr_t) |
bool | operator!= (std::nullptr_t, const CsUniquePointer< T, Deleter > &ptr2) |
bool | operator< (const CsUniquePointer< T1 > &ptr1, const CsUniquePointer< T2 > ptr2) |
bool | operator<= (const CsUniquePointer< T1 > &ptr1, const CsUniquePointer< T2 > ptr2) |
bool | operator> (const CsUniquePointer< T1 > &ptr1, const CsUniquePointer< T2 > ptr2) |
bool | operator>= (const CsUniquePointer< T1 > &ptr1, const CsUniquePointer< T2 > ptr2) |
The CsUniquePointer class contains a pointer to an object and takes exclusive ownership of the lifetime of the object. There is no reference count for a CsUniquePointer since no other smart pointers can point to the given object. Any pointer class which takes responsibility for the lifetime of the object it points to is considered a smart pointer.
When this smart pointer class is destroyed the object it points to will be deleted. This ensures the object is always destroyed when the pointer goes out of scope.
The purpose of a destructor is to clean up the resources owned by the object. Destroying a smart pointer object needs to do a bit more work. It is also responsible for releaseing the dynamic memory allocated to the object the smart pointer was pointing to. Most dynamically allocated objects are destroyed by simply calling the delete operator as shown below.
When using a smart pointer which owns the object it is pointing to, users do not call delete directly. The destructor method is responsible for calling a method in a Deleter class which will release the memory allocated to the object. The exact call in the Deleter class must correspond to the way the object was created.
Allocation | Deleter Class | Destruction |
---|---|---|
new T() | std::default_delete<T> | Default Deleter class, calls operator delete() |
new T[ ] | std::default_delete<T[ ]> | Default Deleter class, calls operator delete[ ] |
CsUniquePointer has a default Deleter class which is sufficient for most objects. If your application requires a custom Deleter class the name of this struct or class must be passed as the second template parameter to CsUniquePointer.
CsUniquePointer::deleter_type |
Typedef for std::unique_ptr<T, Deleter>::deleter_type.
CsUniquePointer::DeleterType |
Typedef for deleter_type;
CsUniquePointer::element_type |
Typedef for std::unique_ptr<T, Deleter>::element_type.
CsUniquePointer::ElementType |
Typedef for element_type.
CsUniquePointer::pointer |
Typedef for std::unique_ptr<T, Deleter>::pointer.
CsUniquePointer::Pointer |
Typedef for pointer.
|
inlineexplicitnoexcept |
Constructs a new CsUniquePointer object and sets the internal pointer to p.
|
inlineexplicitnoexcept |
Constructs a new CsUniquePointer object and sets the internal pointer to p and the deleter to d.
|
inlinenoexcept |
Constructs a new CsUniquePointer by moving ownership from p.
|
default |
Destroys this CsUniquePointer object.
|
default |
Move constructs a new CsUniquePointer from other.
|
inlinenoexcept |
Returns the value of the pointer in the current CsUniquePointer. This smart pointer class still owns the object it is pointing to. No other code should attempt to delete the object.
|
inlinenoexcept |
Equivalent to calling CsUniquePointer::data().
|
inlinenoexcept |
Returns the deleter object which will be used for destruction of this smart pointer.
|
inlinenoexcept |
Returns the deleter object which will be used for destruction of this smart pointer.
|
inlinenoexcept |
Returns true if this CsUniquePointer contains a nullptr, otherwise returns false.
|
inlineexplicitnoexcept |
Returns true if this CsUniquePointer does not contain a nullptr. This method is invoked automatically when a unique pointer is used as a boolean condition.
|
inlinenoexcept |
Converts the current CsUniquePointer to an std::unique_ptr.
|
inlinenoexcept |
Returns true if this CsUniquePointer contains a nullptr, otherwise returns false.
|
inlinenoexcept |
Dereferences this CsUniquePointer and returns the object it points to. If the unique pointer is a nullptr the behavior is undefined.
|
inlinenoexcept |
Dereferences this CsUniquePointer and returns a raw pointer to the object it points to. If the unique pointer is a nullptr the behavior is undefined.
|
default |
Move assigns from other and returns a reference to this object.
|
inlinenoexcept |
Equivalent to calling CsUniquePointer::take().
|
inlinenoexcept |
Assigns other to this CsUniquePointer. If the current unique pointer is not a nullptr then the object it is pointing to will be destroyed.
|
inlinenoexcept |
Swap the current pointer with other.
|
inlinenoexcept |
Releases the ownership of the managed object, if any. The caller is responsible for deleting the object. Sets this object to a nullptr and returns the old pointer value.
|
related |
Constructs a new object of type T by using the given args as the parameter list for the constructor of T.
|
related |
Returns true if ptr1 is not a nullptr, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 do not point to the same object, otherwise returns false.
|
related |
Returns true if ptr2 is not a nullptr, otherwise returns false.
|
related |
Returns true if the value of ptr1 is less than ptr2.
|
related |
Returns true if the value of ptr1 is less than or equal to ptr2.
|
related |
Returns true if ptr1 is a nullptr, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.
|
related |
Returns true if ptr1 and ptr2 point to the same object, otherwise returns false.
|
related |
Returns true if ptr2 is a nullptr, otherwise returns false.
|
related |
Returns true if the value of ptr1 is greater than ptr2.
|
related |
Returns true if the value of ptr1 is greater than or equal to ptr2.