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)
 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
 T&.
 
typedef const T & const_reference
 const T&.
 
typedef T * pointer
 T*.
 
typedef const T * const_pointer
 const T*.
 
typedef T * iterator
 Random-access iterator.
 
typedef const T * const_iterator
 Read-only random-access iterator.
 
typedef std::reverse_iterator< iteratorreverse_iterator
 std::reverse_iterator<iterator>
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 std::reverse_iterator<const_iterator>
 

Public Member Functions

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...
 
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
 See operator[](size_t idx) =.
 
T & front ()
 Gets the first element. More...
 
const T & front () const
 See front.
 
T & back ()
 Gets the last element. More...
 
const T & back () const
 See back.
 
iterator begin () noexcept
 Gets the iterator pointing to the first element. More...
 
const_iterator begin () const noexcept
 See begin.
 
const_iterator cbegin () const noexcept
 Gets the read-only iterator pointing to the first element. More...
 
iterator end () noexcept
 Gets the iterator pointing beyond the last element. More...
 
const_iterator end () const noexcept
 See end.
 
const_iterator cend () const noexcept
 Gets the read-only iterator pointing beyond the last element. More...
 
reverse_iterator rbegin () noexcept
 Gets the reverse iterator pointing to the last element. More...
 
const_reverse_iterator rbegin () const noexcept
 See rbegin.
 
reverse_iterator rend () noexcept
 Gets the reverse iterator pointing ahead of the first element. More...
 
const_reverse_iterator rend () const noexcept
 See rend.
 
const_reverse_iterator crbegin () const noexcept
 Gets the read-only reverse iterator pointing to the last element. More...
 
const_reverse_iterator crend () const noexcept
 Gets the read-only iterator pointing ahead of the first element. More...
 
void swap (ReallocVec &rhs) noexcept
 Swaps vectors. More...
 
size_t size () const noexcept
 Gets the size of the vector. More...
 
size_t capacity () const noexcept
 Gets the maximum number of elements that can be stored without reallocating memory. More...
 
bool empty () const noexcept
 Determines whether the vector is empty. More...
 
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. More...
 
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...
 

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 18 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 135 of file ReallocVec.h.

Member Function Documentation

§ back()

template<class T>
nn::nlib::ReallocVec< T >::back ( )
inline

Gets the last element.

Returns
The last element.

Definition at line 64 of file ReallocVec.h.

§ begin()

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

Gets the iterator pointing to the first element.

Returns
The iterator to the first element.

Definition at line 67 of file ReallocVec.h.

§ 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 95 of file ReallocVec.h.

§ cbegin()

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

Gets the read-only iterator pointing to the first element.

Returns
The read-only iterator to the first element.

Definition at line 69 of file ReallocVec.h.

§ cend()

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

Gets the read-only iterator pointing beyond the last element.

Returns
The read-only iterator pointing beyond the last element.

Definition at line 72 of file ReallocVec.h.

§ clear()

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

Empties the vector. Note that the memory remains allocated.

Empties the vector.

Description
Note that the region storing the strings is freed, but the memory for the vector itself remains allocated.

Definition at line 105 of file ReallocVec.h.

§ crbegin()

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

Gets the read-only reverse iterator pointing to the last element.

Returns
The read-only reverse iterator pointing to the last element.

Definition at line 81 of file ReallocVec.h.

§ crend()

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

Gets the read-only iterator pointing ahead of the first element.

Returns
The read-only iterator pointing ahead of the first element.

Definition at line 84 of file ReallocVec.h.

§ empty()

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

Determines whether the vector is empty.

Returns
Returns true if empty.

Definition at line 96 of file ReallocVec.h.

§ end()

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

Gets the iterator pointing beyond the last element.

Returns
The iterator pointing beyond the last element.

Definition at line 70 of file ReallocVec.h.

§ front()

template<class T>
nn::nlib::ReallocVec< T >::front ( )
inline

Gets the first element.

Returns
The first element.

Definition at line 62 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 45 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 117 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 60 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 55 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 46 of file ReallocVec.h.

§ rbegin()

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

Gets the reverse iterator pointing to the last element.

Returns
The reverse iterator pointing to the last element.

Definition at line 73 of file ReallocVec.h.

§ rend()

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

Gets the reverse iterator pointing ahead of the first element.

Returns
The reverse iterator pointing ahead of the first element.

Definition at line 77 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 97 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 100 of file ReallocVec.h.

§ size()

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

Gets the size of the vector.

Returns
The size of the vector.

Definition at line 94 of file ReallocVec.h.

§ swap()

template<class T>
nn::nlib::ReallocVec< T >::swap ( ReallocVec< T > &  rhs)
inlinenoexcept

Swaps vectors.

Parameters
[in]rhsThe vector to swap.

Definition at line 87 of file ReallocVec.h.


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