Gromacs  2026.0-dev-20241106-9ba7f4d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions
gmx::FixedCapacityVector< typename, size_t > Class Template Reference

#include <gromacs/utility/include/gromacs/utility/fixedcapacityvector.h>

Description

template<typename, size_t>
class gmx::FixedCapacityVector< typename, size_t >

Vector that behaves likes std::vector but has fixed capacity.

Template Parameters
TValue type of elements, should be default constructible
capacity_The maximum number of elements that can be stored.

This class provides a variable size container, but with constant memory usage and can be allocated on the stack and avoid the overhead of dynamic allocation. This is especially useful for small vectors which are set up frequently.

The class supports all methods from std::array, but behaves more like std::vector since it has variable size. In addition to the methods from std::array, from std::vector the methods push_back(), pop_back(), emplace_back() and clear() are supported. In particular, methods that requires reordering, such as insert() and emplace() are not supported to keep the code simple.

The size is 0 at construction and elements can only be added with push_back() and emplace_back().

Note
This class is very similar to the fixed_capacity_vector class proposed for the C++ standard in document P0843r see: http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0843r1.html

Public Types

using value_type = T
 Type of values stored in the vector.
 
using size_type = size_t
 Type for representing size of the vector.
 
using difference_type = ptrdiff_t
 Type for representing difference between two indices.
 
using const_reference = const T &
 Const reference to an element.
 
using const_pointer = const T *
 Const pointer to an element.
 
using const_iterator = const T *
 Const iterator type to an element.
 
using reference = T &
 Reference to an element.
 
using pointer = T *
 Pointer to an element.
 
using iterator = T *
 Iterator type to an element.
 
using reverse_iterator = std::reverse_iterator< iterator >
 Standard reverse iterator.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 Standard reverse iterator.
 

Public Member Functions

 FixedCapacityVector (size_type count=0)
 Constructor, count sets the initial size, 0 by default.
 
const_iterator begin () const noexcept
 Returns a const iterator to the beginning.
 
iterator begin () noexcept
 Returns an iterator to the beginning.
 
const_iterator end () const noexcept
 Returns a const iterator to the end.
 
iterator end () noexcept
 Returns an iterator to the end.
 
const_reverse_iterator rbegin () const noexcept
 Returns a const iterator to the reverse beginning.
 
reverse_iterator rbegin () noexcept
 Returns an iterator to the reverse beginning.
 
const_reverse_iterator rend () const noexcept
 Returns a const iterator to the reverse end.
 
reverse_iterator rend () noexcept
 Returns an iterator to the reverse end.
 
constexpr size_type size () const noexcept
 Returns the size. More...
 
constexpr Index ssize () const noexcept
 Returns the signed size.
 
constexpr bool empty () const noexcept
 Returns whether the vector is empty.
 
constexpr const_reference operator[] (size_type n) const noexcept
 Const access an element.
 
constexpr reference operator[] (size_type n) noexcept
 Access an element.
 
constexpr const_reference at (size_type n) const
 Const access an element, throws an out_of_range exception when out of range.
 
constexpr reference at (size_type n)
 Access an element, throws an out_of_range exception when out of range.
 
constexpr reference front () noexcept
 Returns the first element Returns the first element.
 
constexpr const_reference front () const noexcept
 Returns the first element (const version)
 
constexpr reference back () noexcept
 Returns the last element.
 
constexpr const_reference back () const noexcept
 Returns the last element (const version)
 
constexpr const T * data () const noexcept
 Returns a raw pointer to the contents of the array.
 
constexpr T * data () noexcept
 Returns a raw pointer to the contents of the array.
 
constexpr void push_back (const T &value) noexcept
 Adds element at the end.
 
constexpr void pop_back () noexcept
 Deletes last element.
 
template<class... Args>
constexpr reference emplace_back (Args &&...args)
 Constructs an element at the end.
 
constexpr void resize (const size_type count)
 Resizes the vector, when the new size is larger, new elements are zero initialized.
 
constexpr void clear () noexcept
 Clears content.
 

Static Public Member Functions

static constexpr size_type max_size () noexcept
 Returns the vector capacity (max. number of elements that can be stored)
 
static constexpr size_type capacity () noexcept
 Returns the vector capacity (max. number of elements that can be stored)
 

Member Function Documentation

template<typename , size_t >
constexpr size_type gmx::FixedCapacityVector< typename, size_t >::size ( ) const
inlinenoexcept

Returns the size.

Note
Use ssize for any expression involving arithmetic operations (including loop indices).

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