Regina 7.4 Calculation Engine
|
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. | |
FixedArray & | operator= (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. | |
FixedArray & | operator= (const FixedArray &)=delete |
bool | operator== (const FixedArray &rhs) const |
Determines whether this and the given array are identical. | |
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.
using regina::FixedArray< T >::const_iterator = T const* |
A random-access iterator that gives read-only access to the elements of this array.
using regina::FixedArray< T >::const_reference = T const& |
A constant reference to an individual array element.
using regina::FixedArray< T >::difference_type = ptrdiff_t |
The type used for a signed distance between two iterators.
using regina::FixedArray< T >::iterator = T* |
A random-access iterator that gives read-write access to the elements of this array.
using regina::FixedArray< T >::reference = T& |
A reference to an individual array element.
using regina::FixedArray< T >::size_type = size_t |
The type used for the number of elements in this array.
using regina::FixedArray< T >::value_type = T |
The type of an individual element in this array.
|
inline |
Constructs a new array of the given size.
Every element will be created using the default constructor for T.
size | the number of elements in the new array. |
|
inline |
Constructs a new array of the given size, and initialises every element to the given value.
size | the number of elements in the new array. |
value | the value to assign to every element of the new array. |
|
inline |
Makes a new deep copy of the given array.
src | the array whose contents should be copied. |
|
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.
src | the array whose contents should be moved. |
|
inline |
Creates a new array containing a hard-coded sequence of values.
values | the sequence of values to copy into this new list. |
|
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.
|
inline |
Returns a read-write reference to the last element of this array.
|
inline |
Returns a read-only reference to the last element of this array.
|
inline |
Returns a read-write random-access iterator pointing to the first element of this array.
|
inline |
Returns a read-only random-access iterator pointing to the first element of this array.
|
inline |
Returns a read-only random-access iterator pointing to the first element of this array.
|
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.
|
inline |
Determines whether this array is empty.
This is true if and only if size() == 0
.
true
if and only if this array is empty.
|
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.
|
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.
|
inline |
Returns a read-write reference to the first element of this array.
|
inline |
Returns a read-only reference to the first element of this array.
|
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.
|
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
).
true
if and only if this and the given array are identical.
|
inline |
Returns a read-write reference to the array element at the given index.
index | the index of the element to access. This must be between 0 and size()-1 inclusive. |
|
inline |
Returns a read-only reference to the array element at the given index.
index | the index of the element to access. This must be between 0 and size()-1 inclusive. |
|
inline |
Returns the number of elements in this array.
|
inlinenoexcept |
Swaps the contents of this and the given array.
other | the array whose contents are to be swapped with this. |