Regina 7.4 Calculation Engine
regina::FixedArray< T > Class Template Reference

A lightweight fixed-size random-access array whose size can be provided at runtime. More...

#include <utilities/fixedarray.h>

Public Types

using reference = T&
 A reference to an individual array element.
 
using const_reference = T const&
 A constant reference to an individual array element.
 
using iterator = T*
 A random-access iterator that gives read-write access to the elements of this array.
 
using const_iterator = T const*
 A random-access iterator that gives read-only access to the elements of this array.
 
using value_type = T
 The type of an individual element in this array.
 
using size_type = size_t
 The type used for the number of elements in this array.
 
using difference_type = ptrdiff_t
 The type used for a signed distance between two iterators.
 

Public Member Functions

 FixedArray (size_t size)
 Constructs a new array of the given size.
 
 FixedArray (size_t size, const T &value)
 Constructs a new array of the given size, and initialises every element to the given value.
 
 FixedArray (const FixedArray &src)
 Makes a new deep copy of the given array.
 
 FixedArray (FixedArray &&src) noexcept
 Moves the contents of the given array into this new array.
 
 FixedArray (std::initializer_list< T > values)
 Creates a new array containing a hard-coded sequence of values.
 
 ~FixedArray ()
 Destroys this array.
 
T & operator[] (size_t index)
 Returns a read-write reference to the array element at the given index.
 
const T & operator[] (size_t index) const
 Returns a read-only reference to the array element at the given index.
 
size_t size () const
 Returns the number of elements in this array.
 
bool empty () const
 Determines whether this array is empty.
 
iterator begin ()
 Returns a read-write random-access iterator pointing to the first element of this array.
 
const_iterator begin () const
 Returns a read-only random-access iterator pointing to the first element of this array.
 
iterator end ()
 Returns a read-write random-access iterator pointing beyond the last element of this array.
 
const_iterator end () const
 Returns a read-only random-access iterator pointing beyond the last element of this array.
 
const_iterator cbegin () const
 Returns a read-only random-access iterator pointing to the first element of this array.
 
const_iterator cend () const
 Returns a read-only random-access iterator pointing beyond the last element of this array.
 
const T & front () const
 Returns a read-only reference to the first element of this array.
 
T & front ()
 Returns a read-write reference to the first element of this array.
 
const T & back () const
 Returns a read-only reference to the last element of this array.
 
T & back ()
 Returns a read-write reference to the last element of this array.
 
FixedArrayoperator= (FixedArray &&src) noexcept
 Moves the contents of the given array into this array.
 
void swap (FixedArray< T > &other) noexcept
 Swaps the contents of this and the given array.
 
FixedArrayoperator= (const FixedArray &)=delete
 
bool operator== (const FixedArray &rhs) const
 Determines whether this and the given array are identical.
 

Detailed Description

template<typename T>
class regina::FixedArray< T >

A lightweight fixed-size random-access array whose size can be provided at runtime.

After construction, the size of the array cannot be changed.

This class is intended to be used for temporary working arrays within the implementations of algorithms: it is lightweight and provides the speed of C-style arrays, but avoids the pitfalls of new[] and delete[], instead offering safe and simple stack-based memory mangement and exception safety.

This class is very similar in nature to LightweightSequence, but was born from different needs. It is possible that these two classes will be unified in some future version of Regina.

This class implements C++ move semantics and adheres to the C++ Swappable requirement. It is designed to avoid deep copies wherever possible, even when passing or returning objects by value.

Python
Not present.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using regina::FixedArray< T >::const_iterator = T const*

A random-access iterator that gives read-only access to the elements of this array.

◆ const_reference

template<typename T >
using regina::FixedArray< T >::const_reference = T const&

A constant reference to an individual array element.

◆ difference_type

template<typename T >
using regina::FixedArray< T >::difference_type = ptrdiff_t

The type used for a signed distance between two iterators.

◆ iterator

template<typename T >
using regina::FixedArray< T >::iterator = T*

A random-access iterator that gives read-write access to the elements of this array.

◆ reference

template<typename T >
using regina::FixedArray< T >::reference = T&

A reference to an individual array element.

◆ size_type

template<typename T >
using regina::FixedArray< T >::size_type = size_t

The type used for the number of elements in this array.

◆ value_type

template<typename T >
using regina::FixedArray< T >::value_type = T

The type of an individual element in this array.

Constructor & Destructor Documentation

◆ FixedArray() [1/5]

template<typename T >
regina::FixedArray< T >::FixedArray ( size_t size)
inline

Constructs a new array of the given size.

Precondition
The type T has a default constructor.

Every element will be created using the default constructor for T.

Parameters
sizethe number of elements in the new array.

◆ FixedArray() [2/5]

template<typename T >
regina::FixedArray< T >::FixedArray ( size_t size,
const T & value )
inline

Constructs a new array of the given size, and initialises every element to the given value.

Precondition
The type T has a copy constructor.
Parameters
sizethe number of elements in the new array.
valuethe value to assign to every element of the new array.

◆ FixedArray() [3/5]

template<typename T >
regina::FixedArray< T >::FixedArray ( const FixedArray< T > & src)
inline

Makes a new deep copy of the given array.

Precondition
The type T has a copy assignment operator.
Parameters
srcthe array whose contents should be copied.

◆ FixedArray() [4/5]

template<typename T >
regina::FixedArray< T >::FixedArray ( FixedArray< T > && src)
inlinenoexcept

Moves the contents of the given array into this new array.

This is a fast (constant time) operation.

The array src that was passed will no longer be usable.

Parameters
srcthe array whose contents should be moved.

◆ FixedArray() [5/5]

template<typename T >
regina::FixedArray< T >::FixedArray ( std::initializer_list< T > values)
inline

Creates a new array containing a hard-coded sequence of values.

Precondition
The type T has a copy assignment operator.
Parameters
valuesthe sequence of values to copy into this new list.

◆ ~FixedArray()

template<typename T >
regina::FixedArray< T >::~FixedArray ( )
inline

Destroys this array.

All elements of this array will be destroyed using the destructor for type T. If the elements are pointers whose pointee objects need to be deleted also, you must do this separately before destroying the array itself.

Member Function Documentation

◆ back() [1/2]

template<typename T >
T & regina::FixedArray< T >::back ( )
inline

Returns a read-write reference to the last element of this array.

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

◆ back() [2/2]

template<typename T >
const T & regina::FixedArray< T >::back ( ) const
inline

Returns a read-only reference to the last element of this array.

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

◆ begin() [1/2]

template<typename T >
iterator regina::FixedArray< T >::begin ( )
inline

Returns a read-write random-access iterator pointing to the first element of this array.

Returns
a read-write begin iterator.

◆ begin() [2/2]

template<typename T >
const_iterator regina::FixedArray< T >::begin ( ) const
inline

Returns a read-only random-access iterator pointing to the first element of this array.

Returns
a read-only begin iterator.

◆ cbegin()

template<typename T >
const_iterator regina::FixedArray< T >::cbegin ( ) const
inline

Returns a read-only random-access iterator pointing to the first element of this array.

Returns
a read-only begin iterator.

◆ cend()

template<typename T >
const_iterator regina::FixedArray< T >::cend ( ) const
inline

Returns a read-only random-access iterator pointing beyond the last element of this array.

Note that, because this iterator is past-the-end, it must not be dereferenced.

Returns
a read-only end iterator.

◆ empty()

template<typename T >
bool regina::FixedArray< T >::empty ( ) const
inline

Determines whether this array is empty.

This is true if and only if size() == 0.

Returns
true if and only if this array is empty.

◆ end() [1/2]

template<typename T >
iterator regina::FixedArray< T >::end ( )
inline

Returns a read-write random-access iterator pointing beyond the last element of this array.

Note that, because this iterator is past-the-end, it must not be dereferenced.

Returns
a read-write end iterator.

◆ end() [2/2]

template<typename T >
const_iterator regina::FixedArray< T >::end ( ) const
inline

Returns a read-only random-access iterator pointing beyond the last element of this array.

Note that, because this iterator is past-the-end, it must not be dereferenced.

Returns
a read-only end iterator.

◆ front() [1/2]

template<typename T >
T & regina::FixedArray< T >::front ( )
inline

Returns a read-write reference to the first element of this array.

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

◆ front() [2/2]

template<typename T >
const T & regina::FixedArray< T >::front ( ) const
inline

Returns a read-only reference to the first element of this array.

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

◆ operator=()

template<typename T >
FixedArray & regina::FixedArray< T >::operator= ( FixedArray< T > && src)
inlinenoexcept

Moves the contents of the given array into this array.

It does not matter whether this and the given array are the same size; this array will be resized as required (and this is a cheap operation).

The array that was passed will no longer be usable.

Returns
a reference to this array.

◆ operator==()

template<typename T >
bool regina::FixedArray< T >::operator== ( const FixedArray< T > & rhs) const
inline

Determines whether this and the given array are identical.

This routine compares the elements of both arrays in order using the standard equality operator for the element type T.

It is fine if this array and rhs have different sizes (in which case this comparison will immediately return false).

Returns
true if and only if this and the given array are identical.

◆ operator[]() [1/2]

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

Returns a read-write reference 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 requested array element.

◆ operator[]() [2/2]

template<typename T >
const T & regina::FixedArray< T >::operator[] ( size_t index) const
inline

Returns a read-only reference 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 requested array element.

◆ size()

template<typename T >
size_t regina::FixedArray< T >::size ( ) const
inline

Returns the number of elements in this array.

Returns
the array size.

◆ swap()

template<typename T >
void regina::FixedArray< T >::swap ( FixedArray< T > & other)
inlinenoexcept

Swaps the contents of this and the given array.

Parameters
otherthe array whose contents are to be swapped with this.

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