Gromacs  2020.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions
gmx::FixedCapacityVector< T, capacity > Class Template Reference

#include <gromacs/utility/fixedcapacityvector.h>

Description

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

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

Template Parameters
TValue type of elements.
capacityThe 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

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.
 
size_type size () const noexcept
 Returns the size. More...
 
index ssize () const noexcept
 Returns the signed size.
 
bool empty () const noexcept
 Returns whether the vector is empty.
 
const_reference operator[] (size_type n) const noexcept
 Const access an element.
 
reference operator[] (size_type n) noexcept
 Access an element.
 
const_reference at (size_type n) const
 Const access an element, throws an out_of_range exception when out of range.
 
reference at (size_type n)
 Access an element, throws an out_of_range exception when out of range.
 
reference front () const noexcept
 Returns the first element.
 
reference back () const noexcept
 Returns the last element.
 
const T * data () const noexcept
 Returns a raw pointer to the contents of the array.
 
T * data () noexcept
 Returns a raw pointer to the contents of the array.
 
void push_back (const T &value) noexcept
 Adds element at the end.
 
void pop_back () noexcept
 Deletes last element.
 
template<class... Args>
reference emplace_back (Args &&...args)
 Constructs an element at the end.
 
void clear () noexcept
 Clears content.
 

Member Function Documentation

template<typename T , size_t capacity>
size_type gmx::FixedCapacityVector< T, capacity >::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 file: