Inherits nn::nlib::nlist::NlistBaseT< T >, and nn::nlib::nlist::NlistAlloc< is_empty, AL >.
|
|
typedef BaseType::value_type | value_type |
| Element type T.
|
|
typedef AL | allocator_type |
| Allocator type AL .
|
|
typedef BaseType::size_type | size_type |
| Unsigned integer type (size_t ).
|
|
typedef BaseType::difference_type | difference_type |
| Signed integer type (ptrdiff_t ).
|
|
typedef BaseType::reference | reference |
| T& .
|
|
typedef BaseType::reference | const_reference |
| const T& .
|
|
typedef BaseType::pointer | pointer |
| T* .
|
|
typedef BaseType::const_pointer | const_pointer |
| const T* .
|
|
typedef BaseType::iterator | iterator |
| Forward iterator.
|
|
typedef BaseType::const_iterator | const_iterator |
| Read-only forward iterator.
|
|
template<class T, class AL = std::allocator<char>>
class nn::nlib::Nlist< T, AL >
A container-like class similar to std::vector
that can store objects that do not have copy constructors.
- Template Parameters
-
T | Element type. |
AL | The allocator type. The default is std::allocator<char> . |
- Description
- The following bullet points describe details about the behavior and list cautions for this class.
-
std::push_back
can crash due to an out-of-memory event when elements are added (providing that exceptions are not enabled). With the Nlist
class, the NULL
pointer is returned if adding an element fails, so you can deal with problems by checking the return values.
-
Objects are not relocated. The way
std::vector
generally works is that when elements are added (or when reserve
is called), more memory is allocated and the data is copied to that memory. With Nlist
, new memory is allocated only for the added elements, and there is no relocation of objects.
As a result of this behavior, push_back
is faster than with std::vector
because there are no costs associated with copying the memory required for relocation and freeing the original memory. In addition, memory allocation can be more efficient because you can use a simple allocator like a stack allocator.
-
The coding inside
Nlist
does not make use of an element type T
copy constructor. As a result, an element type T
copy constructor does not need to be defined.
-
With
Nlist
, elements can be added by in-place initialization. Because Nlist
does not use a copy constructor, the standard push_back
function does not need to be implemented.
Elements can be added using the following member functions.
-
T* push_back(void)
: Adds elements created by the default constructor.
-
T* EmplaceBack(argument list to forward to the T constructor)
: Passes an argument list and Nlist
starts the constructor internally to add elements (which avoids invoking the copy constructor).
-
With
Nlist
, you implement forward iterators.
-
There is a list of arrays of different sizes in
Nlist
, so referencing in the forward direction of the iterator is as fast as std::vector
.
-
The execution efficiency of the
std::advance
function is \(O(\log n)\)
.
-
The execution efficiency of the
std::distance
function is \(O(1)\)
.
-
Supports the square brackets operator ([]). However, the execution efficiency is
\(O(\log idx)\)
.
-
The kinds of constructors defined by
Nlist
are limited. The reasons for this limitation are as follows.
-
Avoids out-of-memory problems.
-
The element type does not require a copy constructor.
- Examples:
- msgpack/json/json.cpp, and msgpack/jsonrpc/jsonrpc.cpp.
Definition at line 32 of file Nlist.h.