Regina 7.3 Calculation Engine
Public Types | Public Member Functions | List of all members
regina::ShortArray< T, maxSize > Class Template Reference

A short stack-based array of bounded size. More...

#include <utilities/shortarray.h>

Public Types

using value_type = T
 The type of object stored in the array. More...
 
using size_type = size_t
 The type used for indexing into this array. More...
 
using reference = T &
 A non-const reference to an array element. More...
 
using const_reference = T const &
 A const reference to an array element. More...
 
using iterator = T *
 An iterator type that provides non-const access to the array elements. More...
 
using const_iterator = const T *
 An iterator type that provides const access to the array elements. More...
 

Public Member Functions

constexpr ShortArray ()=default
 Constructs a new empty array. More...
 
constexpr ShortArray (const ShortArray &)=default
 Constructs a new copy of the given array. More...
 
ShortArrayoperator= (const ShortArray &)=default
 Sets this to be a copy of the given array. More...
 
constexpr bool empty () const
 Determines if this array is currently empty. More...
 
constexpr size_t size () const
 Returns the number of elements currently in this array. More...
 
constexpr size_t max_size () const
 Returns the maximum number of elements that can be held by this array. More...
 
T & operator[] (size_t index)
 Gives write access to the array element at the given index. More...
 
constexpr const T & operator[] (size_t index) const
 Gives read-only access to the array element at the given index. More...
 
constexpr const T & front () const
 Returns the first element in the array. More...
 
constexpr const T & back () const
 Returns the last element in the array. More...
 
iterator begin ()
 Returns a read-write iterator pointing to the beginning of this array. More...
 
const_iterator begin () const
 Returns a read-only iterator pointing to the beginning of this array. More...
 
iterator end ()
 Returns a read-write iterator pointing past the end of this array. More...
 
const_iterator end () const
 Returns a read-only iterator pointing past the end of this array. More...
 
void push_back (const T &item)
 Pushes a copy of the given item onto the end of this array. More...
 
void push_back (T &&item)
 Moves the given item onto the end of this array. More...
 
void pop_back ()
 Removes the last item from this array. More...
 
void clear ()
 Removes all elements from this array. More...
 

Detailed Description

template<typename T, size_t maxSize>
class regina::ShortArray< T, maxSize >

A short stack-based array of bounded size.

ShortArray represents a stack-based array whose size is bounded above by the compile-time constant maxSize, but whose size at runtime can vary between 0 and maxSize inclusive.

Here "stack-based" means that the array does not use dynamic memory allocation; instead it reserves space for maxSize elements directly on the stack. In this sense, it is analogous to std::array<T, maxSize> or indeed a plain C-style array T[maxSize]. Like these other types, it is fast to access with very little space or time overhead, but it cannot be moved or swapped in constant time.

Where ShortArray differs from these other types is that its size can vary at runtime. Its default constructor initialises it to size zero, and it supports push_back() and pop_back() operations and a size() query which are all very fast. The size is, however, limited to maxSize, and any attempt to push additional elements beyond this limit will result in undefined behaviour.

This class was designed with very small arrays in mind; an example is the list of embeddings for a (dim-1)-dimensional face in a dim-dimensional triangulationw, which always has size 1 or 2.

This class does not implement move constructors or move assignment, since this cannot be done any faster than a linear-time copy operation. For the same reason, it does not implement its own custom swap functions.

Python
Not present.

Member Typedef Documentation

◆ const_iterator

template<typename T , size_t maxSize>
using regina::ShortArray< T, maxSize >::const_iterator = const T*

An iterator type that provides const access to the array elements.

◆ const_reference

template<typename T , size_t maxSize>
using regina::ShortArray< T, maxSize >::const_reference = T const&

A const reference to an array element.

◆ iterator

template<typename T , size_t maxSize>
using regina::ShortArray< T, maxSize >::iterator = T*

An iterator type that provides non-const access to the array elements.

◆ reference

template<typename T , size_t maxSize>
using regina::ShortArray< T, maxSize >::reference = T&

A non-const reference to an array element.

◆ size_type

template<typename T , size_t maxSize>
using regina::ShortArray< T, maxSize >::size_type = size_t

The type used for indexing into this array.

◆ value_type

template<typename T , size_t maxSize>
using regina::ShortArray< T, maxSize >::value_type = T

The type of object stored in the array.

Constructor & Destructor Documentation

◆ ShortArray() [1/2]

template<typename T , size_t maxSize>
constexpr regina::ShortArray< T, maxSize >::ShortArray ( )
constexprdefault

Constructs a new empty array.

◆ ShortArray() [2/2]

template<typename T , size_t maxSize>
constexpr regina::ShortArray< T, maxSize >::ShortArray ( const ShortArray< T, maxSize > &  )
constexprdefault

Constructs a new copy of the given array.

Member Function Documentation

◆ back()

template<typename T , size_t maxSize>
constexpr const T & regina::ShortArray< T, maxSize >::back ( ) const
inlineconstexpr

Returns the last element in the array.

Precondition
The array is non-empty.
Returns
a const reference to the last element.

◆ begin() [1/2]

template<typename T , size_t maxSize>
iterator regina::ShortArray< T, maxSize >::begin ( )
inline

Returns a read-write iterator pointing to the beginning of this array.

Returns
an iterator pointing to the first element.

◆ begin() [2/2]

template<typename T , size_t maxSize>
const_iterator regina::ShortArray< T, maxSize >::begin ( ) const
inline

Returns a read-only iterator pointing to the beginning of this array.

Returns
an iterator pointing to the first element.

◆ clear()

template<typename T , size_t maxSize>
void regina::ShortArray< T, maxSize >::clear ( )
inline

Removes all elements from this array.

◆ empty()

template<typename T , size_t maxSize>
constexpr bool regina::ShortArray< T, maxSize >::empty ( ) const
inlineconstexpr

Determines if this array is currently empty.

Returns
true if and only if the array contains no elements.

◆ end() [1/2]

template<typename T , size_t maxSize>
iterator regina::ShortArray< T, maxSize >::end ( )
inline

Returns a read-write iterator pointing past the end of this array.

Returns
an iterator after the last element.

◆ end() [2/2]

template<typename T , size_t maxSize>
const_iterator regina::ShortArray< T, maxSize >::end ( ) const
inline

Returns a read-only iterator pointing past the end of this array.

Returns
an iterator after the last element.

◆ front()

template<typename T , size_t maxSize>
constexpr const T & regina::ShortArray< T, maxSize >::front ( ) const
inlineconstexpr

Returns the first element in the array.

Precondition
The array is non-empty.
Returns
a const reference to the first element.

◆ max_size()

template<typename T , size_t maxSize>
constexpr size_t regina::ShortArray< T, maxSize >::max_size ( ) const
inlineconstexpr

Returns the maximum number of elements that can be held by this array.

Returns
the maximum allowable number of elements.

◆ operator=()

template<typename T , size_t maxSize>
ShortArray & regina::ShortArray< T, maxSize >::operator= ( const ShortArray< T, maxSize > &  )
default

Sets this to be a copy of the given array.

Returns
a reference to this array.

◆ operator[]() [1/2]

template<typename T , size_t maxSize>
T & regina::ShortArray< T, maxSize >::operator[] ( size_t  index)
inline

Gives write access to the array element at the given index.

Parameters
indexthe index of the element to access; this must be between 0 and size()-1 inclusive.
Returns
a reference to the array element at the given index.

◆ operator[]() [2/2]

template<typename T , size_t maxSize>
constexpr const T & regina::ShortArray< T, maxSize >::operator[] ( size_t  index) const
inlineconstexpr

Gives read-only access to the array element at the given index.

Parameters
indexthe index of the element to access; this must be between 0 and size()-1 inclusive.
Returns
a const reference to the array element at the given index.

◆ pop_back()

template<typename T , size_t maxSize>
void regina::ShortArray< T, maxSize >::pop_back ( )
inline

Removes the last item from this array.

Precondition
The array is non-empty.

◆ push_back() [1/2]

template<typename T , size_t maxSize>
void regina::ShortArray< T, maxSize >::push_back ( const T &  item)
inline

Pushes a copy of the given item onto the end of this array.

Precondition
The array has size strictly less than maxSize.
Parameters
itemthe item to add to this array.

◆ push_back() [2/2]

template<typename T , size_t maxSize>
void regina::ShortArray< T, maxSize >::push_back ( T &&  item)
inline

Moves the given item onto the end of this array.

Precondition
The array has size strictly less than maxSize.
Parameters
itemthe item to add to this array.

◆ size()

template<typename T , size_t maxSize>
constexpr size_t regina::ShortArray< T, maxSize >::size ( ) const
inlineconstexpr

Returns the number of elements currently in this array.

Returns
the array size.

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

Copyright © 1999-2023, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).