Regina 7.0 Calculation Engine
Public Types | Public Member Functions | List of all members
regina::ListView< Container > Class Template Reference

A lightweight object that can be used for iteration and random access to all elements of a given list. More...

#include <utilities/listview.h>

Public Types

using value_type = typename Container::value_type
 The type of element that is stored in this list. More...
 
using size_type = typename Container::size_type
 The type used for indexing into this list. More...
 
using reference = typename Container::const_reference
 A reference to a list element. More...
 
using const_reference = typename Container::const_reference
 A reference to a list element. More...
 
using iterator = typename Container::const_iterator
 The iterator type for this list view. More...
 
using const_iterator = typename Container::const_iterator
 The iterator type for this list view. More...
 

Public Member Functions

 ListView (const Container &list)
 Returns a view for the given list. More...
 
 ListView (const ListView &)=default
 Creates a new copy of the given list view. More...
 
ListViewoperator= (const ListView &)=default
 Sets this to be a copy of the given list view. More...
 
bool empty () const
 Determines if this list is empty. More...
 
size_type size () const
 Returns the number of elements in this list. More...
 
const_reference operator[] (size_type index) const
 Returns the requested element of this list. More...
 
const_reference front () const
 Returns the first element of this list. More...
 
const_reference back () const
 Returns the last element of this list. More...
 
const_iterator begin () const
 Returns an iterator pointing to the first element. More...
 
const_iterator end () const
 Returns an iterator pointing beyond the last element. More...
 

Detailed Description

template<class Container>
class regina::ListView< Container >

A lightweight object that can be used for iteration and random access to all elements of a given list.

Typically a ListView would be returned from a class member function to grant the user some basic read-only access to a much richer private data structure, in a way that allows the internal data structure to change at some later date without affecting the public API.

The ListView class supports two different ways of representing a list:

End users should always store ListView objects using auto, not by explicitly writing out the full ListView type. One reason for this is that, if/when Regina moves to C++20, the ListView class will most likely be removed completely (in favour of the new C++20 ranges library).

ListView objects are small enough to pass by value and swap with std::swap(), with no need for any specialised move operations or swap functions.

Template Parameters
Containerthe internal type of the list that this object grants access to. This type must support at least the same operations as this class itself, except for the copy semantics. In particular, both std::vector and regina::MarkedVector types (as well as many other standard container types) are suitable.

Member Typedef Documentation

◆ const_iterator

template<class Container >
using regina::ListView< Container >::const_iterator = typename Container::const_iterator

The iterator type for this list view.

Both iterator and const_iterator are the same, since this class only offers read-only access to the underlying list.

◆ const_reference

template<class Container >
using regina::ListView< Container >::const_reference = typename Container::const_reference

A reference to a list element.

Both reference and const_reference are the same, since this class only offers read-only access to the underlying list.

◆ iterator

template<class Container >
using regina::ListView< Container >::iterator = typename Container::const_iterator

The iterator type for this list view.

Both iterator and const_iterator are the same, since this class only offers read-only access to the underlying list.

◆ reference

template<class Container >
using regina::ListView< Container >::reference = typename Container::const_reference

A reference to a list element.

Both reference and const_reference are the same, since this class only offers read-only access to the underlying list.

◆ size_type

template<class Container >
using regina::ListView< Container >::size_type = typename Container::size_type

The type used for indexing into this list.

◆ value_type

template<class Container >
using regina::ListView< Container >::value_type = typename Container::value_type

The type of element that is stored in this list.

Constructor & Destructor Documentation

◆ ListView() [1/2]

template<class Container >
regina::ListView< Container >::ListView ( const Container list)

Returns a view for the given list.

Parameters
listthe list that this object will access. Internally, this object will store a reference to list (which means list needs to exist for at least as long as this object).

◆ ListView() [2/2]

template<class Container >
regina::ListView< Container >::ListView ( const ListView< Container > &  )
default

Creates a new copy of the given list view.

Member Function Documentation

◆ back()

template<class Container >
ListView< Container >::const_reference regina::ListView< Container >::back
inline

Returns the last element of this list.

Precondition
This list is not empty.
Returns
the last element in this list.

◆ begin()

template<class Container >
ListView< Container >::const_iterator regina::ListView< Container >::begin
inline

Returns an iterator pointing to the first element.

Python
ListView is an iterable object: instead of providing begin() and end(), it implements the Python iterable interface.
Returns
an iterator at the beginning of this list.

◆ empty()

template<class Container >
bool regina::ListView< Container >::empty
inline

Determines if this list is empty.

Returns
true if and only if this list is empty.

◆ end()

Returns an iterator pointing beyond the last element.

Python
ListView is an iterable object: instead of providing begin() and end(), it implements the Python iterable interface.
Returns
an iterator beyond the end of this list.

◆ front()

template<class Container >
ListView< Container >::const_reference regina::ListView< Container >::front
inline

Returns the first element of this list.

Precondition
This list is not empty.
Returns
the first element in this list.

◆ operator=()

template<class Container >
ListView & regina::ListView< Container >::operator= ( const ListView< Container > &  )
default

Sets this to be a copy of the given list view.

Returns
a reference to this list view.

◆ operator[]()

template<class Container >
ListView< Container >::const_reference regina::ListView< Container >::operator[] ( size_type  index) const
inline

Returns the requested element of this list.

Parameters
indexindicates which element to return; this must be between 0 and size()-1 inclusive.
Returns
the (index)th element in this list.

◆ size()

template<class Container >
ListView< Container >::size_type regina::ListView< Container >::size
inline

Returns the number of elements in this list.

Returns
the number of elements.

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

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