UniquePtr
owns the pointer, and when it goes out of scope, the pointer is released by the destructor using the method specified by DEL.
More...
#include "nn/nlib/UniquePtr.h"
Inherits nn::nlib::detail::UniquePtrBase< T, DEL, DEL_EMPTY >.
|
void | reset (T *p=0) noexcept |
| Replaces a pointer. The replaced pointer is deleted. More...
|
|
T * | get () const noexcept |
| Gets the pointer that is being stored.
|
|
T * | release () noexcept |
| Release ownership of the pointer and returns the pointer. More...
|
|
void | swap (UniquePtr &rhs) noexcept |
| Swaps the pointer that is being stored. More...
|
|
size_t | GetHash () const |
| Computes the hash value for the pointer and returns the calculation result.
|
|
DEL & | get_deleter () |
| Gets the deleter.
|
|
const DEL & | get_deleter () const |
| Gets the deleter.
|
|
| operator bool () const |
| Returns true if holding a valid pointer.
|
|
|
constexpr | UniquePtr () noexcept |
| Instantiates the object with default parameters (default constructor).
|
|
constexpr | UniquePtr (nullptr_t) noexcept |
| This function is called if nullptr has been passed to a parameter.
|
|
| UniquePtr (T *p) noexcept |
| Sets a pointer. More...
|
|
| UniquePtr (T *p, const DEL &del) |
| Sets a pointer and a deleter. More...
|
|
UniquePtr & | assign (UniquePtr &rhs, move_tag) |
| Assigns the object by using swap for a move.
|
|
| UniquePtr (UniquePtr &rhs, move_tag) |
| Instantiates the object by using swap for a move.
|
|
| UniquePtr (UniquePtr &&rhs) |
| Instantiates the object (move constructor). This function is useful when using C++11.
|
|
UniquePtr & | operator= (UniquePtr &&rhs) |
| Move assignment operator. This function is useful when using C++11.
|
|
| ~UniquePtr () noexcept |
| Destructor. If the pointer is not NULL, executes the deleter and deletes.
|
|
AddRef< T >::type | operator* () const |
| Dereferences the pointer.
|
|
T * | operator-> () const noexcept |
| Returns the pointer.
|
|
UniquePtr & | operator= (nullptr_t) noexcept |
| Substitutes for nullptr .
|
|
template<class T, class DEL = DefaultDelete<T>>
class nn::nlib::UniquePtr< T, DEL >
UniquePtr
owns the pointer, and when it goes out of scope, the pointer is released by the destructor using the method specified by DEL.
- Template Parameters
-
T | The object type. |
DEL | The deleter type. The default execution is delete/delete[] . |
- Description
- Write your code in the following way.
UniquePtr<MyObject> myObjPtr(new MyObject());
UniquePtr<char[]> myArrayPtr(new char[1024]);
operator==
and operator!=
functions have been implemented for comparing UniquePtr
objects. If a pointer to an array is set, you can use operator[]
.
- In the C++11 environment (which supports template aliases),
std:: unique_ptr
is made a template alias.
- Internal Implementation Memo
- In the current implementation, a
UniquePtr
derived class cannot be substituted for the UniquePtr
base class.
- Examples:
- exi/multithread/multithread.cpp, exi/script/script.cpp, exi/simple1/simple1.cpp, exi/simple2/simple2.cpp, exi/textparser/textparser.cpp, misc/threading/future/future.cpp, msgpack/json/json.cpp, msgpack/jsonrpc/jsonrpc.cpp, msgpack/jsonrpc/server.cpp, msgpack/msgpack1/msgpack1.cpp, msgpack/msgpack2/msgpack2.cpp, oss/binarypatch/binarypatch.cpp, and succinct/ngc/ngc.cpp.
Definition at line 109 of file UniquePtr.h.
◆ UniquePtr() [1/2]
template<class T, class DEL = DefaultDelete<T>>
Sets a pointer.
- Parameters
-
Definition at line 119 of file UniquePtr.h.
◆ UniquePtr() [2/2]
template<class T, class DEL = DefaultDelete<T>>
Sets a pointer and a deleter.
- Parameters
-
[in] | p | A pointer. |
[in] | del | A deleter. |
Definition at line 120 of file UniquePtr.h.
◆ release()
template<class T, class DEL = DefaultDelete<T>>
Release ownership of the pointer and returns the pointer.
- Returns
- The pointer.
Definition at line 146 of file UniquePtr.h.
◆ reset()
template<class T, class DEL = DefaultDelete<T>>
Replaces a pointer. The replaced pointer is deleted.
- Parameters
-
- Description
- If the parameter is omitted,
NULL
is set for p.
- Examples:
- succinct/ngc/ngc.cpp.
Definition at line 128 of file UniquePtr.h.
◆ swap()
template<class T, class DEL = DefaultDelete<T>>
Swaps the pointer that is being stored.
- Parameters
-
[in,out] | rhs | The UniquePtr object being swapped. |
Definition at line 151 of file UniquePtr.h.
The documentation for this class was generated from the following files: