Gromacs
2026.0-dev-20241106-9ba7f4d
|
#include <gromacs/utility/include/gromacs/utility/fixedcapacityvector.h>
Vector that behaves likes std::vector but has fixed capacity.
T | Value 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()
.
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) | |
|
inlinenoexcept |
Returns the size.