ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::SmallVector< T, N, A > Class Template Reference

a vector with room for \( N \) items inside itself More...

#include <ADS/sequence/SmallVector.h>

Inheritance diagram for ADS::SmallVector< T, N, A >:

Public types

using value_type = T
 the type of the items
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances
using reference = T &
 a reference to an item
using const_reference = const T &
 a constant reference to an item
using pointer = T *
 a pointer to an item
using const_pointer = const T *
 a constant pointer to an item
using iterator = T *
 the iterator on the items
using const_iterator = const T *
 the iterator on the constant items
using reverse_iterator = std::reverse_iterator< iterator >
 the iterator on the items, backwards
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 the iterator on the constant items, backwards
using allocator_type = A
 the type of the allocator

Public member functions

 SmallVector (void) noexcept
 the empty vector, its items inside it
 SmallVector (const A &alloc) noexcept
 the empty vector, its items inside it, the allocator alloc
 SmallVector (std::size_t n, const T &x=T())
 \( n \) items made from \( x \)
 SmallVector (std::initializer_list< T > items)
 the vector of the given items, in their order
template<std::input_iterator I, std::sentinel_for< I > S>
 SmallVector (I first, S last)
 the items of [ first , last ), in their order
 SmallVector (const SmallVector &other)
 a copy of other
 SmallVector (const SmallVector &other)
 a copy of other, on the allocator that select_on_container_copy_construction() gives
 SmallVector (const SmallVector &other, const A &alloc)
 a copy of other, on alloc
 SmallVector (SmallVector &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
 the items of other, which is left empty
 SmallVector (SmallVector &&other, const A &alloc)
 the items of other, which is left empty, on alloc: its memory if the allocators are equal, else its items moved one by one
SmallVector & operator= (const SmallVector &other)
 a copy of other
SmallVector & operator= (const SmallVector &other)
 the copy assignment, with the allocator of other if it propagates
SmallVector & operator= (SmallVector &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
 the items of other, which is left empty
SmallVector & operator= (SmallVector &&other)
 the move assignment: the memory of other if its allocator propagates or is equal, else its items moved one by one
allocator_type get_allocator (void) const
 the allocator of the items
 ~SmallVector ()
 destroys the items, and frees the memory of the allocator if any
void swap (SmallVector &other)
 exchanges the items with other
bool empty (void) const
 true if there is no item
std::size_t size (void) const
 the number of items, \( n \)
std::size_t capacity (void) const
 the room, \( c \) items, at least \( N \)
bool small (void) const
 the items are inside the vector
T * data (void)
 the vector of the items
const T * data (void) const
 the vector of the items, constant
iterator begin (void)
 the iterator on the first item
iterator end (void)
 the iterator past the last item
const_iterator begin (void) const
 the constant iterator on the first item
const_iterator end (void) const
 the constant iterator past the last item
const_iterator cbegin (void) const
 the constant iterator on the first item
const_iterator cend (void) const
 the constant iterator past the last item
reverse_iterator rbegin (void)
 the iterator on the last item, backwards
reverse_iterator rend (void)
 the iterator before the first item, backwards
const_reverse_iterator rbegin (void) const
 the constant iterator on the last item, backwards
const_reverse_iterator rend (void) const
 the constant iterator before the first item, backwards
T & operator[] (std::size_t i)
 the item at the index \( i \)
const T & operator[] (std::size_t i) const
 the item at the index \( i \), constant
T & front (void)
 the first item
const T & front (void) const
 the first item, constant
T & back (void)
 the last item
const T & back (void) const
 the last item, constant
void push_back (const T &x)
 \( x \) at the end, \( O( 1 ) \) amortized; \( x \) may be an item of the vector
void push_back (T &&x)
 \( x \) at the end, moved, as push_back() above
template<class... Args>
T & emplace_back (Args &&... args)
 an item made from the arguments at the end, which may refer to items of the vector, \( O( 1 ) \) amortized
void pop_back (void)
 removes the last item
void reserve (std::size_t n)
 room for \( n \) items
void resize (std::size_t n, const T &x=T())
 \( n \) items, those added made from \( x \)
void clear (void)
 removes the items, keeping the memory
bool operator== (const SmallVector &o) const
 the same items in the same order

Detailed description

template<class T, std::size_t N = 8, class A = std::allocator< T >>
class ADS::SmallVector< T, N, A >

a vector with room for \( N \) items inside itself

Member typedef documentation

◆ allocator_type

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::allocator_type = A

the type of the allocator

◆ const_iterator

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::const_iterator = const T *

the iterator on the constant items

◆ const_pointer

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::const_pointer = const T *

a constant pointer to an item

◆ const_reference

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::const_reference = const T &

a constant reference to an item

◆ const_reverse_iterator

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::const_reverse_iterator = std::reverse_iterator< const_iterator >

the iterator on the constant items, backwards

◆ difference_type

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::iterator = T *

the iterator on the items

◆ pointer

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::pointer = T *

a pointer to an item

◆ reference

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::reference = T &

a reference to an item

◆ reverse_iterator

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::reverse_iterator = std::reverse_iterator< iterator >

the iterator on the items, backwards

◆ size_type

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T, std::size_t N = 8, class A = std::allocator< T >>
using ADS::SmallVector< T, N, A >::value_type = T

the type of the items

Constructor and destructor documentation

◆ SmallVector() [1/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( void )
inlinenoexcept

the empty vector, its items inside it

◆ SmallVector() [2/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( const A & alloc)
inlineexplicitnoexcept

the empty vector, its items inside it, the allocator alloc

◆ SmallVector() [3/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( std::size_t n,
const T & x = T() )
explicit

\( n \) items made from \( x \)

◆ SmallVector() [4/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( std::initializer_list< T > items)

the vector of the given items, in their order

◆ SmallVector() [5/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
template<std::input_iterator I, std::sentinel_for< I > S>
ADS::SmallVector< T, N, A >::SmallVector ( I first,
S last )

the items of [ first , last ), in their order

◆ SmallVector() [6/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( const SmallVector< T, N, A > & other)

a copy of other

◆ SmallVector() [7/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( const SmallVector< T, N, A > & other)
inline

a copy of other, on the allocator that select_on_container_copy_construction() gives

◆ SmallVector() [8/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( const SmallVector< T, N, A > & other,
const A & alloc )

a copy of other, on alloc

◆ SmallVector() [9/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( SmallVector< T, N, A > && other) const
noexcept

the items of other, which is left empty

◆ SmallVector() [10/10]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::SmallVector ( SmallVector< T, N, A > && other,
const A & alloc )

the items of other, which is left empty, on alloc: its memory if the allocators are equal, else its items moved one by one

◆ ~SmallVector()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
ADS::SmallVector< T, N, A >::~SmallVector ( )

destroys the items, and frees the memory of the allocator if any

Member function documentation

◆ back() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
T & ADS::SmallVector< T, N, A >::back ( void )
inlinenodiscard

the last item

Precondition
the vector is not empty

◆ back() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const T & ADS::SmallVector< T, N, A >::back ( void ) const
inlinenodiscard

the last item, constant

Precondition
the vector is not empty

◆ begin() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
iterator ADS::SmallVector< T, N, A >::begin ( void )
inlinenodiscard

the iterator on the first item

◆ begin() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const_iterator ADS::SmallVector< T, N, A >::begin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ capacity()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
std::size_t ADS::SmallVector< T, N, A >::capacity ( void ) const
inlinenodiscard

the room, \( c \) items, at least \( N \)

◆ cbegin()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const_iterator ADS::SmallVector< T, N, A >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const_iterator ADS::SmallVector< T, N, A >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ clear()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
void ADS::SmallVector< T, N, A >::clear ( void )

removes the items, keeping the memory

◆ data() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
T * ADS::SmallVector< T, N, A >::data ( void )
inlinenodiscard

the vector of the items

◆ data() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const T * ADS::SmallVector< T, N, A >::data ( void ) const
inlinenodiscard

the vector of the items, constant

◆ emplace_back()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
template<class... Args>
T & ADS::SmallVector< T, N, A >::emplace_back ( Args &&... args)

an item made from the arguments at the end, which may refer to items of the vector, \( O( 1 ) \) amortized

In pseudocode (section 4.2), \( A[ 0 .. c - 1 ] \) the room, inside the vector while \( c = N \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{emplace\_back}( \mathit{args} ) \cr 2 & \quad x \gets \text{the item of } \mathit{args}\quad \triangleright \ \text{built before any move, since } \mathit{args} \text{ may lie in } A \cr 3 & \quad \textbf{if}\ n = c\ \textbf{then}\quad \triangleright \ \text{full: a block twice as large} \cr 4 & \qquad B \gets 2 c \text{ places from the allocator};\ \text{move } A[ 0 .. n - 1 ] \text{ into } B \cr 5 & \qquad \text{give } A \text{ back unless it is the inner buffer};\ ( A , c ) \gets ( B , 2 c ) \cr 6 & \quad A[ n ] \gets x;\ n \gets n + 1;\ \textbf{return}\ A[ n - 1 ] \end{array}} \]

◆ empty()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
bool ADS::SmallVector< T, N, A >::empty ( void ) const
inlinenodiscard

true if there is no item

◆ end() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
iterator ADS::SmallVector< T, N, A >::end ( void )
inlinenodiscard

the iterator past the last item

◆ end() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const_iterator ADS::SmallVector< T, N, A >::end ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ front() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
T & ADS::SmallVector< T, N, A >::front ( void )
inlinenodiscard

the first item

Precondition
the vector is not empty

◆ front() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const T & ADS::SmallVector< T, N, A >::front ( void ) const
inlinenodiscard

the first item, constant

Precondition
the vector is not empty

◆ get_allocator()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
allocator_type ADS::SmallVector< T, N, A >::get_allocator ( void ) const
inlinenodiscard

the allocator of the items

◆ operator=() [1/4]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
SmallVector & ADS::SmallVector< T, N, A >::operator= ( const SmallVector< T, N, A > & other)
inline

the copy assignment, with the allocator of other if it propagates

◆ operator=() [2/4]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
SmallVector & ADS::SmallVector< T, N, A >::operator= ( const SmallVector< T, N, A > & other)

a copy of other

◆ operator=() [3/4]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
SmallVector & ADS::SmallVector< T, N, A >::operator= ( SmallVector< T, N, A > && other)
inline

the move assignment: the memory of other if its allocator propagates or is equal, else its items moved one by one

◆ operator=() [4/4]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
SmallVector & ADS::SmallVector< T, N, A >::operator= ( SmallVector< T, N, A > && other) const
noexcept

the items of other, which is left empty

◆ operator==()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
bool ADS::SmallVector< T, N, A >::operator== ( const SmallVector< T, N, A > & o) const
inlinenodiscard

the same items in the same order

◆ operator[]() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
T & ADS::SmallVector< T, N, A >::operator[] ( std::size_t i)
inlinenodiscard

the item at the index \( i \)

Precondition
\( i < n \)

◆ operator[]() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const T & ADS::SmallVector< T, N, A >::operator[] ( std::size_t i) const
inlinenodiscard

the item at the index \( i \), constant

Precondition
\( i < n \)

◆ pop_back()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
void ADS::SmallVector< T, N, A >::pop_back ( void )

removes the last item

Precondition
the vector is not empty

◆ push_back() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
void ADS::SmallVector< T, N, A >::push_back ( const T & x)
inline

\( x \) at the end, \( O( 1 ) \) amortized; \( x \) may be an item of the vector

◆ push_back() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
void ADS::SmallVector< T, N, A >::push_back ( T && x)
inline

\( x \) at the end, moved, as push_back() above

◆ rbegin() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
reverse_iterator ADS::SmallVector< T, N, A >::rbegin ( void )
inlinenodiscard

the iterator on the last item, backwards

◆ rbegin() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const_reverse_iterator ADS::SmallVector< T, N, A >::rbegin ( void ) const
inlinenodiscard

the constant iterator on the last item, backwards

◆ rend() [1/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
reverse_iterator ADS::SmallVector< T, N, A >::rend ( void )
inlinenodiscard

the iterator before the first item, backwards

◆ rend() [2/2]

template<class T, std::size_t N = 8, class A = std::allocator< T >>
const_reverse_iterator ADS::SmallVector< T, N, A >::rend ( void ) const
inlinenodiscard

the constant iterator before the first item, backwards

◆ reserve()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
void ADS::SmallVector< T, N, A >::reserve ( std::size_t n)

room for \( n \) items

◆ resize()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
void ADS::SmallVector< T, N, A >::resize ( std::size_t n,
const T & x = T() )

\( n \) items, those added made from \( x \)

◆ size()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
std::size_t ADS::SmallVector< T, N, A >::size ( void ) const
inlinenodiscard

the number of items, \( n \)

◆ small()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
bool ADS::SmallVector< T, N, A >::small ( void ) const
inlinenodiscard

the items are inside the vector

◆ swap()

template<class T, std::size_t N = 8, class A = std::allocator< T >>
void ADS::SmallVector< T, N, A >::swap ( SmallVector< T, N, A > & other)

exchanges the items with other


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