nlib
nn::nlib::ReallocVec< T > Class Template Reference

The class for realloc-based implementations of vectors with POD-type elements. More...

#include "nn/nlib/ReallocVec.h"

Public Types

typedef void *(* ReallocFunc) (void *, size_t) NLIB_NOEXCEPT_FUNCPTR
 The type for functions corresponding to realloc.
 
Typedef
typedef T value_type
 Element type T.
 
typedef size_t size_type
 Unsigned integer type (size_t).
 
typedef ptrdiff_t difference_type
 Signed integer type (ptrdiff_t).
 
typedef T & reference
 A reference to an element.
 
typedef const T & const_reference
 Read-only reference to an element.
 
typedef T * pointer
 Pointer to the element.
 
typedef const T * const_pointer
 Read-only pointer to an element.
 
typedef T * iterator
 A random-access iterator.
 
typedef const T * const_iterator
 Read-only random-access iterator.
 
typedef std::reverse_iterator< iteratorreverse_iterator
 A reverse iterator.
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 Read-only reverse iterator.
 

Public Member Functions

ReallocFunc GetRealloc () const noexcept
 Gets the specified realloc function. More...
 
bool push_back (const T &v) noexcept
 Adds an element to the vector. More...
 
bool pop_back () noexcept
 Deletes an element from the end of the vector. More...
 
T & operator[] (size_t idx)
 Gets the nth element, where n is specified by idx. More...
 
const T & operator[] (size_t idx) const
 The const decoration version of the above function.
 
T & front ()
 Gets a reference to the first element.
 
const T & front () const
 The const decoration version of the above function.
 
T & back ()
 Gets a reference to the last element.
 
const T & back () const
 The const decoration version of the above function.
 
iterator begin () noexcept
 Gets the iterator pointing to the first element.
 
const_iterator begin () const noexcept
 Gets the read-only iterator pointing to the first element.
 
const_iterator cbegin () const noexcept
 Gets the read-only iterator pointing to the first element.
 
iterator end () noexcept
 Gets the iterator pointing beyond the last element.
 
const_iterator end () const noexcept
 Gets the read-only iterator pointing beyond the last element.
 
const_iterator cend () const noexcept
 Gets the read-only iterator pointing beyond the last element.
 
reverse_iterator rbegin () noexcept
 Gets the reverse iterator pointing to the last element.
 
const_reverse_iterator rbegin () const noexcept
 Gets the read-only reverse iterator pointing to the last element.
 
reverse_iterator rend () noexcept
 Gets the reverse iterator pointing ahead of the first element.
 
const_reverse_iterator rend () const noexcept
 Gets the read-only reverse iterator pointing ahead of the first element.
 
const_reverse_iterator crbegin () const noexcept
 Gets the read-only reverse iterator pointing to the last element.
 
const_reverse_iterator crend () const noexcept
 Gets the read-only reverse iterator pointing ahead of the first element.
 
size_t size () const noexcept
 Returns the number of stored elements.
 
size_t capacity () const noexcept
 Gets the maximum number of elements that can be stored without reallocating memory. More...
 
bool empty () const noexcept
 Returns true if the number of stored elements is 0, or returns false otherwise.
 
bool reserve (size_t n) noexcept
 Makes it possible to store as many as n elements without reallocating memory. More...
 
bool resize (size_t n) noexcept
 Changes the number of elements. More...
 
void clear () noexcept
 Empties the vector. Note that the memory remains allocated.
 
void shrink_to_fit () noexcept
 Adjusts the size of allocated memory to exactly fit the current number of elements.
 
iterator insert (iterator pos, const T &val)
 Inserts an element in the position specified by pos. More...
 
Constructor, Destructor, and Initialization
constexpr ReallocVec () noexcept
 Uses std::realloc with the default constructor.
 
constexpr ReallocVec (ReallocFunc func) noexcept
 Enables the user to specify the realloc function with the constructor. More...
 
 ReallocVec (ReallocVec &&rhs) noexcept
 Instantiates the object (move constructor).
 
ReallocVecoperator= (ReallocVec &&rhs) noexcept
 Move assignment operator.
 

Detailed Description

template<class T>
class nn::nlib::ReallocVec< T >

The class for realloc-based implementations of vectors with POD-type elements.

Template Parameters
TThe element type. This type must be POD.
Description
T must be aligned to an alignment guaranteed by realloc.

Definition at line 32 of file ReallocVec.h.

Constructor & Destructor Documentation

◆ ReallocVec()

template<class T >
constexpr nn::nlib::ReallocVec< T >::ReallocVec ( ReallocFunc  func)
inlineexplicitnoexcept

Enables the user to specify the realloc function with the constructor.

Parameters
[in]funcThe realloc function.

Definition at line 184 of file ReallocVec.h.

Member Function Documentation

◆ capacity()

template<class T>
nn::nlib::ReallocVec< T >::capacity ( ) const
inlinenoexcept

Gets the maximum number of elements that can be stored without reallocating memory.

Returns
The number of elements.

Definition at line 146 of file ReallocVec.h.

◆ GetRealloc()

template<class T>
nn::nlib::ReallocVec< T >::GetRealloc ( ) const
inlinenoexcept

Gets the specified realloc function.

Returns
The realloc function.

Definition at line 99 of file ReallocVec.h.

◆ insert()

template<class T>
nn::nlib::ReallocVec< T >::insert ( iterator  pos,
const T &  val 
)
inline

Inserts an element in the position specified by pos.

Parameters
[in]posThe insertion position.
[in]valThe element to insert.
Returns
The iterator pointing to the inserted element.

Definition at line 166 of file ReallocVec.h.

◆ operator[]()

template<class T>
nn::nlib::ReallocVec< T >::operator[] ( size_t  idx)
inline

Gets the nth element, where n is specified by idx.

Parameters
[in]idxAn index.
Returns
The nth character (where n is set in idx.)

Definition at line 114 of file ReallocVec.h.

◆ pop_back()

template<class T>
nn::nlib::ReallocVec< T >::pop_back ( )
inlinenoexcept

Deletes an element from the end of the vector.

Returns
Returns true if deleted successfully.

Definition at line 109 of file ReallocVec.h.

◆ push_back()

template<class T>
nn::nlib::ReallocVec< T >::push_back ( const T &  v)
inlinenoexcept

Adds an element to the vector.

Parameters
[in]vThe element to add.
Returns
Returns true if added successfully.

Definition at line 100 of file ReallocVec.h.

◆ reserve()

template<class T>
nn::nlib::ReallocVec< T >::reserve ( size_t  n)
inlinenoexcept

Makes it possible to store as many as n elements without reallocating memory.

Parameters
[in]nNumber of elements.
Returns
Returns true when successful.

Definition at line 148 of file ReallocVec.h.

◆ resize()

template<class T>
nn::nlib::ReallocVec< T >::resize ( size_t  n)
inlinenoexcept

Changes the number of elements.

Parameters
[in]nNumber of elements.
Returns
Returns true when successful.
Description
Note that when the number of elements is increased, those additional elements have undefined values.

Definition at line 149 of file ReallocVec.h.


The documentation for this class was generated from the following files: