Regina 7.0 Calculation Engine
|
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... | |
ListView & | operator= (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... | |
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:
ListView(container)
. This uses the generic ListView<Container> class template. There is no need to explicitly specify the ListView template arguments.ListView(array, size)
or ListView(begin, end)
. Here begin and end are an iterator pair (that is, begin == array
and end == array + size
). This syntax uses the specialised ListView<Element*> class template. Again, there is no need to explicitly specify the ListView template arguments.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.
Container | the 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. |
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.
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.
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.
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.
using regina::ListView< Container >::size_type = typename Container::size_type |
The type used for indexing into this list.
using regina::ListView< Container >::value_type = typename Container::value_type |
The type of element that is stored in this list.
regina::ListView< Container >::ListView | ( | const Container & | list | ) |
Returns a view for the given list.
list | the 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). |
|
default |
Creates a new copy of the given list view.
|
inline |
Returns the last element of this list.
|
inline |
|
inline |
Determines if this list is empty.
true
if and only if this list is empty.
|
inline |
|
inline |
Returns the first element of this list.
|
default |
Sets this to be a copy of the given list view.
|
inline |
Returns the requested element of this list.
index | indicates which element to return; this must be between 0 and size()-1 inclusive. |
|
inline |
Returns the number of elements in this list.