Clingo
Loading...
Searching...
No Matches
CppClingo::Util::small_vector< T, N > Class Template Reference

A vector that misuses the begin, end and capacity pointers to store elements. More...

#include <small_vector.hh>

Public Types

using value_type = T
 The value type.
 
using iterator = T *
 The iterator type.
 
using const_iterator = T const *
 The const iterator type.
 
using reference = T &
 The reference type.
 
using const_reference = T const &
 The const reference type.
 
using pointer = T *
 The pointer type.
 
using const_pointer = T const *
 The const pointer type.
 

Public Member Functions

 small_vector ()=default
 Construct an empty vector.
 
 small_vector (small_vector const &other)
 Copy construct the vector.
 
 small_vector (small_vector &&other) noexcept
 Move construct the vector.
 
template<std::input_iterator It, std::sentinel_for< It > Is>
 small_vector (It begin, Is end)
 Initialize vector from an iterator range.
 
template<std::input_iterator It, std::sentinel_for< It > Is>
void assign (It first, Is last)
 Assign the vector.
 
auto operator= (small_vector const &other) -> small_vector &
 Copy assign the vector.
 
auto operator= (small_vector &&other) noexcept -> small_vector &
 Move assign the vector.
 
void resize (size_t n)
 Resize to the given size.
 
auto size () const -> size_t
 Get the size of the vector.
 
auto empty () const -> bool
 Check if the vector is empty.
 
auto capacity () const -> size_t
 Get the capacity of the vector.
 
auto begin () -> iterator
 Get an iterator to the beginning of the vector.
 
auto begin () const -> const_iterator
 Get a const iterator to the beginning of the vector.
 
auto cbegin () const -> const_iterator
 Get a const iterator to the beginning of the vector.
 
auto end () -> iterator
 Get an iterator to the end of the vector.
 
auto end () const -> const_iterator
 Get a const iterator to the end of the vector.
 
auto cend () const -> const_iterator
 Get a const iterator to the end of the vector.
 
auto data () -> iterator
 Get a pointer to the stored C array.
 
auto data () const -> const_iterator
 Get a const pointer to the stored C array.
 
auto cdata () const -> const_iterator
 Get a const pointer to the stored C array.
 
auto operator[] (size_t i) -> reference
 Get the element at the given index.
 
auto operator[] (size_t i) const -> const_reference
 Get the element at the given index.
 
void reserve (size_t n)
 Reserve space for at least n elements.
 
auto front () -> reference
 Get the first element in the vector.
 
auto front () const -> const_reference
 Get the first element in the vector.
 
auto back () -> reference
 Get the last element in the vector.
 
auto back () const -> const_reference
 Get the last element in the vector.
 
auto erase (iterator it) -> iterator
 Erase the given element.
 
auto erase (iterator first, iterator last) -> iterator
 Erase the given range of elements.
 
template<class... U>
void emplace (const_iterator loc, U &&...args)
 Emplace an element before the given iterator.
 
template<class... U>
void emplace_back (U &&...args)
 Emplace an element after the last element.
 
void push_back (value_type const &x)
 Append an element after the last element.
 
void pop_back ()
 Pop the last element.
 
void clear () noexcept
 Clear the vector.
 
 ~small_vector () noexcept
 Deconstruct the vector.
 

Friends

auto operator<=> (small_vector const &lhs, small_vector const &rhs)
 
auto operator== (small_vector const &lhs, small_vector const &rhs)
 

Detailed Description

template<class T, size_t N = 2>
requires (std::is_nothrow_destructible_v<T> && std::is_nothrow_move_constructible_v<T>)
class CppClingo::Util::small_vector< T, N >

A vector that misuses the begin, end and capacity pointers to store elements.

This optimization makes it well-suited to store a large number of vectors with up to N elements witout allocating. Value N is best chosen to not extend the size of the vector.

Member Function Documentation

◆ clear()

template<class T , size_t N = 2>
void CppClingo::Util::small_vector< T, N >::clear ( )
inlinenoexcept

Clear the vector.

Note that this frees allocated storage.


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