regina::LightweightSequence< T > Class Template Reference

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 ()
| 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...
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...

## Detailed Description

### template<typename T>
class regina::LightweightSequence< T >

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.

Python:
  Not present.

## Member Typedef Documentation

## const_iterator

template<typename T >

typedef const T* regina::LightweightSequence< T >::const_iterator

An iterator type for read-only access to the elements of a sequence.

Such a type can be dereferenced (yielding a const reference to type T), and manipulated using the usual pointer arithmetic (such as `p++`, `–p`, `p += n`, and so on).

## iterator

template<typename T >

typedef T* regina::LightweightSequence< T >::iterator

An iterator type for read-write access to the elements of a sequence.

Such a type can be dereferenced (yielding a reference to type T), and manipulated using the usual pointer arithmetic (such as `p++`, `–p`, `p += n`, and so on).

## Constructor & Destructor Documentation

## LightweightSequence() [1/2]

template<typename T >

regina::LightweightSequence< T >::LightweightSequence | ( |  | ) |

inline

Creates a new empty sequence; that is, a sequence of size zero.

This sequence can be resized by calling init().

## LightweightSequence() [2/2]

template<typename T >

regina::LightweightSequence< T >::LightweightSequence | ( | size_t | size | ) |

inline

Create a new sequence containing the given number of elements.

The elements themselves will be initialised using the default constructor for type T.

Parameters

  size | the number of elements in the new sequence.

## ~LightweightSequence()

template<typename T >

regina::LightweightSequence< T >::~LightweightSequence | ( |  | ) |

inline

Destroys this sequence and all of its elements.

All elements of the sequence 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 sequence itself.

## Member Function Documentation

## begin() [1/2]

template<typename T >

LightweightSequence< T >::iterator regina::LightweightSequence< T >::begin | ( |  | ) |

inline

Returns a read-write iterator that points to the first element of the sequence.

Note that an iterator is simply a pointer to an element of the sequence, and so by dereferencing an iterator you can change the corresponding element of the sequence directly.

Returns
  a read-write begin iterator.

## begin() [2/2]

template<typename T >

LightweightSequence< T >::const_iterator regina::LightweightSequence< T >::begin | ( |  | ) | const

inline

Returns a read-only iterator that points to the first element of the sequence.

Note that a const_iterator is simply a const pointer to an element of the sequence, and so by dereferencing a const_iterator you can access (but not change) the corresponding element of the sequence.

Returns
  a read-only begin iterator.

## end() [1/2]

template<typename T >

LightweightSequence< T >::iterator regina::LightweightSequence< T >::end | ( |  | ) |

inline

Returns a read-write iterator that points beyond the last element of the sequence.

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

Returns
  a read-write past-the-end iterator.

## end() [2/2]

template<typename T >

LightweightSequence< T >::const_iterator regina::LightweightSequence< T >::end | ( |  | ) | const

inline

Returns a read-only iterator that points beyond the last element of the sequence.

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

Returns
  a read-only past-the-end iterator.

## init()

template<typename T >

void regina::LightweightSequence< T >::init | ( | size_t | size = `0` | ) |

inline

Resizes this sequence to contain the given number of elements.

All existing elements in this sequence will be destroyed, using the default destructor for type T. If the elements are pointers whose pointee objects need to be deleted also, you must do this separately before calling init().

The elements of the sequence after this routine is called will be initialised using the default constructor for type T.

Warning
  Calling init() is an expensive operation, in that it will always force a reallocation of the underlying storage (even if the new size is smaller than the old).

Parameters

  size | the number of elements that the sequence will contain after this routine is called.

## operator<()

template<typename T >

bool regina::LightweightSequence< T >::operator< | ( | const LightweightSequence< T > & | rhs | ) | const

inline

Tests whether this sequence is lexicographically smaller than the given sequence.

The sequences need not be the same size.

Parameters

  rhs | the sequence to compare with this.

Returns
  `true` if this is strictly lexicographically smaller than rhs, or `false` if this is either lexicographically greater than or equal to rhs.

## operator==()

template<typename T >

bool regina::LightweightSequence< T >::operator== | ( | const LightweightSequence< T > & | rhs | ) | const

inline

Tests whether this and the given sequence are identical.

The sequences need not be the same size, though if the sizes are different then this routine will return `false` immediately.

Parameters

  rhs | the sequence to compare with this.

Returns
  `true` if and only if this and the given sequence are identical.

## operator[]() [1/2]

template<typename T >

T regina::LightweightSequence< T >::operator[] | ( | size_t | pos | ) | const

inline

Returns a copy of the element at the given index in the sequence.

Parameters

  pos | the index of the requested element; this must be between 0 and size()-1 inclusive.

Returns
  a copy of the requested element.

## operator[]() [2/2]

template<typename T >

T & regina::LightweightSequence< T >::operator[] | ( | size_t | pos | ) |

inline

Returns a reference to the element at the given index in the sequence.

Parameters

  pos | the index of the requested element; this must be between 0 and size()-1 inclusive.

Returns
  a reference to the requested element.

## size()

template<typename T >

size_t regina::LightweightSequence< T >::size | ( |  | ) | const

inline

Returns the number of elements in this sequence.

This can be changed (in a destructive way) by calling init().

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

- utilities/sequence.h

Copyright © 1999-2016, 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).