|
ADS
Algorithms and Data Structures
|
a vector with room for \( N \) items inside itself More...
#include <ADS/sequence/SmallVector.h>
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 | |
a vector with room for \( N \) items inside itself
| using ADS::SmallVector< T, N, A >::allocator_type = A |
the type of the allocator
| using ADS::SmallVector< T, N, A >::const_iterator = const T * |
the iterator on the constant items
| using ADS::SmallVector< T, N, A >::const_pointer = const T * |
a constant pointer to an item
| using ADS::SmallVector< T, N, A >::const_reference = const T & |
a constant reference to an item
| using ADS::SmallVector< T, N, A >::const_reverse_iterator = std::reverse_iterator< const_iterator > |
the iterator on the constant items, backwards
| using ADS::SmallVector< T, N, A >::difference_type = std::ptrdiff_t |
the type of the distances
| using ADS::SmallVector< T, N, A >::iterator = T * |
the iterator on the items
| using ADS::SmallVector< T, N, A >::pointer = T * |
a pointer to an item
| using ADS::SmallVector< T, N, A >::reference = T & |
a reference to an item
| using ADS::SmallVector< T, N, A >::reverse_iterator = std::reverse_iterator< iterator > |
the iterator on the items, backwards
| using ADS::SmallVector< T, N, A >::size_type = std::size_t |
the type of the sizes
| using ADS::SmallVector< T, N, A >::value_type = T |
the type of the items
|
inlinenoexcept |
the empty vector, its items inside it
|
inlineexplicitnoexcept |
the empty vector, its items inside it, the allocator alloc
|
explicit |
\( n \) items made from \( x \)
| ADS::SmallVector< T, N, A >::SmallVector | ( | std::initializer_list< T > | items | ) |
the vector of the given items, in their order
| ADS::SmallVector< T, N, A >::SmallVector | ( | I | first, |
| S | last ) |
the items of [ first , last ), in their order
| ADS::SmallVector< T, N, A >::SmallVector | ( | const SmallVector< T, N, A > & | other | ) |
a copy of other
|
inline |
a copy of other, on the allocator that select_on_container_copy_construction() gives
| ADS::SmallVector< T, N, A >::SmallVector | ( | const SmallVector< T, N, A > & | other, |
| const A & | alloc ) |
a copy of other, on alloc
|
noexcept |
the items of other, which is left empty
| 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
| ADS::SmallVector< T, N, A >::~SmallVector | ( | ) |
destroys the items, and frees the memory of the allocator if any
|
inlinenodiscard |
the last item
|
inlinenodiscard |
the last item, constant
|
inlinenodiscard |
the iterator on the first item
|
inlinenodiscard |
the constant iterator on the first item
|
inlinenodiscard |
the room, \( c \) items, at least \( N \)
|
inlinenodiscard |
the constant iterator on the first item
|
inlinenodiscard |
the constant iterator past the last item
| void ADS::SmallVector< T, N, A >::clear | ( | void | ) |
removes the items, keeping the memory
|
inlinenodiscard |
the vector of the items
|
inlinenodiscard |
the vector of the items, constant
| 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}} \]
|
inlinenodiscard |
true if there is no item
|
inlinenodiscard |
the iterator past the last item
|
inlinenodiscard |
the constant iterator past the last item
|
inlinenodiscard |
the first item
|
inlinenodiscard |
the first item, constant
|
inlinenodiscard |
the allocator of the items
|
inline |
the copy assignment, with the allocator of other if it propagates
| SmallVector & ADS::SmallVector< T, N, A >::operator= | ( | const SmallVector< T, N, A > & | other | ) |
a copy of other
|
inline |
the move assignment: the memory of other if its allocator propagates or is equal, else its items moved one by one
|
noexcept |
the items of other, which is left empty
|
inlinenodiscard |
the same items in the same order
|
inlinenodiscard |
the item at the index \( i \)
|
inlinenodiscard |
the item at the index \( i \), constant
| void ADS::SmallVector< T, N, A >::pop_back | ( | void | ) |
removes the last item
|
inline |
\( x \) at the end, \( O( 1 ) \) amortized; \( x \) may be an item of the vector
|
inline |
\( x \) at the end, moved, as push_back() above
|
inlinenodiscard |
the iterator on the last item, backwards
|
inlinenodiscard |
the constant iterator on the last item, backwards
|
inlinenodiscard |
the iterator before the first item, backwards
|
inlinenodiscard |
the constant iterator before the first item, backwards
| void ADS::SmallVector< T, N, A >::reserve | ( | std::size_t | n | ) |
room for \( n \) items
| void ADS::SmallVector< T, N, A >::resize | ( | std::size_t | n, |
| const T & | x = T() ) |
\( n \) items, those added made from \( x \)
|
inlinenodiscard |
the number of items, \( n \)
|
inlinenodiscard |
the items are inside the vector
| void ADS::SmallVector< T, N, A >::swap | ( | SmallVector< T, N, A > & | other | ) |
exchanges the items with other