chsvlib
chsv helper source code
sbo_vector< ElementType, sbo_threshold, Allocator > Class Template Reference

Implements a vector with customizable small buffer optimization. More...

#include <chsvmemex.h>

Collaboration diagram for sbo_vector< ElementType, sbo_threshold, Allocator >:

Public Types

typedef ElementType value_type
 A type of a vector element.
 
typedef ElementType * pointer
 A type of a pointer to a vector element.
 
typedef ElementType & reference
 A type of a reference to a vector element.
 
typedef const ElementType * const_pointer
 A type of a pointer to an immutable vector element.
 
typedef const ElementType & const_reference
 A type of a reference to an immutable vector element.
 
typedef std::size_t size_type
 A type capable of holding a vector size.
 
typedef std::ptrdiff_t difference_type
 A type capable of holding a difference between any two iterators within a vector.
 
typedef Allocator allocator_type
 A type of the allocator used by the vector in cases when heap allocation is required.
 
typedef impl_do_not_initialize_t do_not_initialize_t
 Used to create vectors with uninitialized memory.
 
typedef ElementType * iterator
 A type of a contiguous and random-access iterator of the vector.
 
typedef const ElementType * const_iterator
 A type of a contiguous and random-access iterator of an immutable vector.
 
typedef std::reverse_iterator< iteratorreverse_iterator
 A type of an iterator traversing contents of vector in the reverse order.
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 

Public Member Functions

 sbo_vector ()=default
 Default constructor.
 
 sbo_vector (const Allocator &allocator) noexcept
 A constructor which creates a default-constructed empty vector with a custom allocator. More...
 
 sbo_vector (const sbo_vector &right, const Allocator &allocator)
 Constructs a copy of a vector with a custom allocator. More...
 
 sbo_vector (const sbo_vector &right)
 The copy constructor. More...
 
 sbo_vector (sbo_vector &&right, const Allocator &allocator) noexcept(std::is_nothrow_move_constructible< ElementType >::value &&Implementation::allocator_always_equal< Allocator >::value)
 Creates a vector moving in another vector of the same type but with a specified allocator instead of one used by the original vector. More...
 
 sbo_vector (sbo_vector &&right) noexcept(std::is_nothrow_move_constructible< ElementType >::value)
 The move constructor. More...
 
template<class IteratorBegin , class IteratorEnd , class = std::enable_if_t<std::is_base_of<std::input_iterator_tag, typename std::iterator_traits<IteratorBegin>::iterator_category>::value && std::is_base_of<std::input_iterator_tag, typename std::iterator_traits<IteratorEnd>::iterator_category>::value>>
 sbo_vector (IteratorBegin begin, IteratorEnd end, const Allocator &allocator=Allocator())
 Constructor initializing contents of the created vector with elements given by a range specified by a pair of iterators. More...
 
 sbo_vector (std::size_t count, const ElementType &val, const Allocator &allocator=Allocator())
 Constructor initializing the created vector with copies of a value. . More...
 
 sbo_vector (std::size_t count, const Allocator &allocator=Allocator())
 Constructor creating a vector of a given size. . More...
 
 sbo_vector (std::size_t count, do_not_initialize_t, const Allocator &allocator=Allocator())
 Constructor which creates a vector omitting initialization of the allocated elements. . More...
 
template<class ValueType , class = std::enable_if_t<std::is_convertible<ElementType, ValueType>::value>>
 sbo_vector (std::initializer_list< ValueType > init_list, const Allocator &allocator=Allocator())
 Constructor initializing contents of the created vector with elements of a given std::initializer_list object. More...
 
 ~sbo_vector ()
 The destructor of the vector.
 
sbo_vectoroperator= (const sbo_vector &right)
 The copy-assignment operator. More...
 
sbo_vectoroperator= (sbo_vector &&right)
 The move-assignment operator. More...
 
const ElementType & operator[] (std::size_t off) const noexcept
 A subscript operator implementing read-only access to an arbitrary element of the vector by index. More...
 
ElementType & operator[] (std::size_t off) noexcept
 A subscript operator implementing modifying access to an arbitrary element of the vector by index. More...
 
const ElementType & at (std::size_t off) const noexcept
 A functional read-only accessor of a vector element by its index. More...
 
ElementType & at (std::size_t off) noexcept
 A functional modifying accessor of a vector element by its index. More...
 
const ElementType & front () const noexcept
 Returns a read-only reference to the first element of the vector. More...
 
ElementType & front () noexcept
 Returns a mutable reference to the first element of the vector. More...
 
const ElementType & back () const noexcept
 Returns a read-only reference to the last element of the vector. More...
 
ElementType & back () noexcept
 Returns a mutable reference to the last element of the vector. More...
 
const_iterator begin () const noexcept
 Returns a read-only iterator associated with the first element of the vector, or, if the vector is empty, the past-the-end iterator.
 
const_iterator cbegin () const noexcept
 Returns a read-only iterator associated with the first element of the vector, or, if the vector is empty, the past-the-end iterator.
 
iterator begin () noexcept
 Returns an iterator associated with the first element of the vector, or, if the vector is empty, the past-the-end iterator.
 
const_iterator end () const noexcept
 Returns the past-the-end iterator associated with a pseudo-element beyond the last element of the vector.
 
const_iterator cend () const noexcept
 Returns the past-the-end iterator associated with a pseudo-element beyond the last element of the vector.
 
iterator end () noexcept
 Returns the past-the-end iterator associated with a pseudo-element beyond the last element of the vector.
 
reverse_iterator rbegin ()
 Returns a reverse iterator associated with the last element of the vector, or, if the vector is empty, the past-the-end reverse iterator.
 
const_reverse_iterator rbegin () const
 Returns a read-only reverse iterator associated with the last element of the vector, or, if the vector is empty, the past-the-end reverse iterator.
 
const_reverse_iterator crbegin () const
 Returns a read-only reverse iterator associated with the last element of the vector, or, if the vector is empty, the past-the-end reverse iterator.
 
reverse_iterator rend ()
 Returns the past-the-end reverse iterator associated with a pseudo-element before the first element of the vector.
 
const_reverse_iterator rend () const
 Returns the past-the-end reverse iterator, with read-only access, associated with a pseudo-element before the first element of the vector.
 
const_reverse_iterator crend () const
 Returns the past-the-end reverse iterator, with read-only access, associated with a pseudo-element before the first element of the vector.
 
const ElementType * data () const noexcept
 Returns a pointer to the buffer of the vector with read-only access.
 
ElementType * data () noexcept
 Returns a pointer to the buffer of the mutable vector.
 
std::size_t size () const noexcept
 Returns a number of elements currently being stored within the vector.
 
std::size_t capacity () const noexcept
 Returns the capacity of the vector, i.e. a number of elements the vector is capable of storing without any reallocations. More...
 
bool empty () const noexcept
 Checks whether the vector is empty.
 
void reserve (std::size_t new_cap)
 Reserves space to store at least a given number of elements without reallocations. More...
 
void resize (std::size_t new_size)
 Changes the size of the vector default-constructing new elements, if necessary. . More...
 
void resize (std::size_t new_size, const ElementType &value)
 Changes the size of the vector copy-constructing new elements from a parameter value, if necessary. . More...
 
void resize (std::size_t new_size, do_not_initialize_t)
 Changes the size of the vector without initializing memory allocated for any new elements, if there are any. . More...
 
template<class ... ElementConstructionParams>
auto emplace_back (ElementConstructionParams &&... params) -> std::enable_if_t< std::is_constructible< ElementType, ElementConstructionParams &&... >::value, iterator >
 Constructs a new element at the back of the vector from a given set of parameters. More...
 
template<class ... ElementConstructionParams>
auto emplace (const_iterator itWhere, ElementConstructionParams &&... params) -> std::enable_if_t< std::is_constructible< ElementType, ElementConstructionParams &&... >::value, iterator >
 Constructs a new element before a position specified by an iterator. More...
 
void push_back (const ElementType &val)
 Adds a copy of a specified value as a new element at the end of the vector.
 
void push_back (ElementType &&val)
 Adds a specified value as a new element at the end of the vector.
 
iterator erase (const_iterator first, const_iterator last)
 Erases elements given by a pair of iterators from the vector. More...
 
void clear ()
 Clears contents of the vector.
 
void shrink_to_fit ()
 Reduces the capacity of the vector, performing any necessary reallocations, to a minimal value sufficient to store the current number of elements in the vector.
 
allocator_type get_allocator () const
 Returns a copy of an allocator used by an instance of vector to allocate memory on heap.
 
void swap (sbo_vector &right)
 Swaps contents of the vector with another vector. More...
 

Static Public Attributes

static constexpr do_not_initialize_t do_not_initialize = do_not_initialize_t{}
 A value used to disambiguate a non-initializing overload of the vector constructors.
 

Detailed Description

template<class ElementType, std::size_t sbo_threshold, class Allocator = std::allocator<ElementType>>
class Chusov::Memory::sbo_vector< ElementType, sbo_threshold, Allocator >

Implements a vector with customizable small buffer optimization.

Template Parameters
ElementTypeA type of elements stored within the vector.
sbo_thresholdA maximal number of elements stored in a stack buffer.
AllocatorA type of an allocator used when allocations in a heap are performed.

The class defines a vector with a buffer on stack capable of storing at most sbo_threshold elements. When the threshold is reached, the data of the vector is reallocated in heap.


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