Inherits nn::nlib::nlist::NlistBaseT< T >, and nn::nlib::nlist::NlistAlloc< is_empty, AL >.
|
size_type | size () const noexcept |
| Returns the number of stored elements. More...
|
|
size_type | capacity () const noexcept |
| Returns the number of allocated elements. More...
|
|
bool | empty () const noexcept |
| Checks whether the container is empty. More...
|
|
bool | resize (size_type n) noexcept |
| Resizes the container. More...
|
|
bool | reserve (size_type n) noexcept |
| Allocates memory for n number of elements. More...
|
|
pointer | push_back () |
| Adds an element to the end and initializes it with the default constructor. More...
|
|
bool | pop_back () noexcept |
| Deletes the last element. More...
|
|
void | swap (Nlist &rhs) noexcept |
| Swaps the container.
|
|
void | clear () noexcept |
| Clears the container.
|
|
allocator_type | get_allocator () const noexcept |
| Gets the allocator. More...
|
|
const_reference | back () const |
| The same as back .
|
|
reference | back () |
| Returns a reference to the last element. More...
|
|
const_reference | front () const |
| The same as front .
|
|
reference | front () |
| Returns a reference to the first element. More...
|
|
const_reference | operator[] (size_type idx) const |
| The same as operator[](size_t idx) .
|
|
reference | operator[] (size_type idx) |
| Uses an index to reference an element. More...
|
|
iterator | begin () noexcept |
| Returns the iterator pointing to the beginning of the container. More...
|
|
const_iterator | begin () const noexcept |
| Returns the iterator pointing to the beginning of the container. More...
|
|
const_iterator | cbegin () const noexcept |
| Returns the iterator pointing to the beginning of the container. More...
|
|
iterator | end () noexcept |
| Returns the iterator pointing to the end of the container. More...
|
|
const_iterator | end () const noexcept |
| Returns the iterator pointing to the end of the container. More...
|
|
const_iterator | cend () const noexcept |
| Returns the iterator pointing to the end of the container. More...
|
|
void | shrink_to_fit () noexcept |
| Returns allocated memory, if possible.
|
|
template<class A1 > |
pointer | EmplaceBack (const A1 &a1) |
| Adds elements in-place. More...
|
|
template<class A1 , class A2 > |
pointer | EmplaceBack (const A1 &a1, const A2 &a2) |
| Adds elements in-place. More...
|
|
template<class A1 , class A2 , class A3 > |
pointer | EmplaceBack (const A1 &a1, const A2 &a2, const A3 &a3) |
| Adds elements in-place. More...
|
|
template<class A1 , class A2 , class A3 , class A4 > |
pointer | EmplaceBack (const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) |
| Adds elements in-place. More...
|
|
template<class A1 , class A2 , class A3 , class A4 , class A5 > |
pointer | EmplaceBack (const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) |
| Adds elements in-place. More...
|
|
void | Clobber () noexcept |
| Returns the container empty without calling the element destructor and without releasing the memory for the container. More...
|
|
|
| Nlist () noexcept |
| Instantiates the object with default parameters (default constructor). Creates an empty container.
|
|
| Nlist (const AL &al) noexcept |
| Specifies an allocator. Creates an empty container.
|
|
| ~Nlist () noexcept |
| Destructor.
|
|
Nlist & | assign (Nlist &rhs, move_tag) |
| Assigns the object by using swap for a move.
|
|
| Nlist (Nlist &rhs, move_tag) |
| Instantiates the object by using swap for a move.
|
|
| Nlist (Nlist &&rhs) |
| Instantiates the object (move constructor). This function is useful when using C++11.
|
|
Nlist & | operator= (Nlist &&rhs) |
| Move assignment operator. This function is useful when using C++11.
|
|
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/jsonrpc/jsonrpc.cpp.
Definition at line 19 of file Nlist.h.