Regina Calculation Engine
|
A lightweight class for storing a random-access sequence of objects. More...
#include <utilities/sequence.h>
Classes | |
struct | Less |
A binary function object that compares sequences lexicographically, for use in containers that hold pointers to sequences. More... | |
class | SubsequenceCompareFirstPtr |
A binary function object for comparing subsequences, for use in associative containers whose keys are pointers to sequences. More... | |
Public Types | |
typedef T * | iterator |
An iterator type for read-write access to the elements of a sequence. More... | |
typedef const T * | const_iterator |
An iterator type for read-only access to the elements of a sequence. More... | |
Public Member Functions | |
LightweightSequence () | |
Creates a new empty sequence; that is, a sequence of size zero. More... | |
LightweightSequence (size_t size) | |
Create a new sequence containing the given number of elements. More... | |
LightweightSequence (const LightweightSequence &src) | |
Create a copy of the given sequence. More... | |
LightweightSequence (LightweightSequence &&src) noexcept | |
Moves the contents of the given sequence to this new sequence. More... | |
~LightweightSequence () | |
Destroys this sequence and all of its elements. More... | |
void | init (size_t size=0) |
Resizes this sequence to contain the given number of elements. More... | |
size_t | size () const |
Returns the number of elements in this sequence. More... | |
T | operator[] (size_t pos) const |
Returns a copy of the element at the given index in the sequence. More... | |
T & | operator[] (size_t pos) |
Returns a reference to the element at the given index in the sequence. More... | |
iterator | begin () |
Returns a read-write iterator that points to the first element of the sequence. More... | |
const_iterator | begin () const |
Returns a read-only iterator that points to the first element of the sequence. More... | |
iterator | end () |
Returns a read-write iterator that points beyond the last element of the sequence. More... | |
const_iterator | end () const |
Returns a read-only iterator that points beyond the last element of the sequence. More... | |
LightweightSequence< T > & | operator= (const LightweightSequence &src) |
Converts this into a copy of the given sequence. More... | |
LightweightSequence< T > & | operator= (LightweightSequence &&src) noexcept |
Moves the contents of the given sequence to this sequence. More... | |
bool | operator== (const LightweightSequence &rhs) const |
Tests whether this and the given sequence are identical. More... | |
bool | operator< (const LightweightSequence &rhs) const |
Tests whether this sequence is lexicographically smaller than the given sequence. More... | |
A lightweight class for storing a random-access sequence of objects.
This class is intended as a lightweight substitute for std::vector, especially when working with temporary sequences that are frequently created and destroyed. The underlying storage just uses a native C-style array, and the C++ class wrapper provides the usual mechanisms for safe and simple memory management.
The size (number of elements) of a sequence can be changed, but this should not be done lightly. Unlike std::vector, resizing a sequence is an expensive operation that deletes all existing contents of the sequence and forces a reallocation of the underlying storage. See init() for details.
This class is designed to avoid deep copies wherever possible. In particular, it supports C++11 move construtors and move assignment.