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

A specialisation of ListView for working with lists stored in a C-style array whose size is not known at compile-time. More...

#include <utilities/listview.h>

Public Types

using value_type = Element
 The type of element that is stored in this list. More...
 
using size_type = size_t
 The type used for indexing into this list. More...
 
using reference = const Element &
 A reference to a list element. More...
 
using const_reference = const Element &
 A reference to a list element. More...
 
using iterator = const Element *
 The iterator type for this list view. More...
 
using const_iterator = const Element *
 The iterator type for this list view. More...
 

Public Member Functions

 ListView (const Element *array, size_t size)
 Returns a view for the given C-style array, presented as an array with size. More...
 
 ListView (const Element *begin, const Element *end)
 Returns a view for the given C-style array, presented as an iterator pair. 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 a C++ iterator pointing to the first element of this list. More...
 
const_iterator end () const
 Returns a C++ iterator pointing beyond the last element of this list. More...
 
auto __iter__ () const
 Returns a Python iterator over the elements of this list. More...
 
bool operator== (const ListView &other) const
 Determines whether this and the given list view are accessing the same underlying C-style array. More...
 
bool operator!= (const ListView &other) const
 Determines whether this and the given list view are accessing different underlying C-style arrays. More...
 

Detailed Description

template<typename Element>
class regina::ListView< Element * >

A specialisation of ListView for working with lists stored in a C-style array whose size is not known at compile-time.

See the generic ListView class documentation for full details on how this class works and how to use it.

Python
As with the generic ListView template classes, Python will automatically translate any C++ ListView object into an internal lightweight class that supports both iteration and indexing at the Python level.
Template Parameters
Elementthe type of element stored in the C-style array. This should not be a const type; the const modifier will added automatically where necessary through the class interface.

Member Typedef Documentation

◆ const_iterator

template<typename Element >
using regina::ListView< Element * >::const_iterator = const Element*

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<typename Element >
using regina::ListView< Element * >::const_reference = const Element&

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<typename Element >
using regina::ListView< Element * >::iterator = const Element*

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<typename Element >
using regina::ListView< Element * >::reference = const Element&

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<typename Element >
using regina::ListView< Element * >::size_type = size_t

The type used for indexing into this list.

◆ value_type

template<typename Element >
using regina::ListView< Element * >::value_type = Element

The type of element that is stored in this list.

Constructor & Destructor Documentation

◆ ListView() [1/3]

template<class Element >
regina::ListView< Element * >::ListView ( const Element *  array,
size_t  size 
)
inline

Returns a view for the given C-style array, presented as an array with size.

Internally, this object will store a pointer to the array, which means the array needs to exist for at least as long as this object.

Python
Not present.
Parameters
arraythe pointer to the C-style array.
sizethe number of elements in the C-style array.

◆ ListView() [2/3]

template<class Element >
regina::ListView< Element * >::ListView ( const Element *  begin,
const Element *  end 
)
inline

Returns a view for the given C-style array, presented as an iterator pair.

Internally, this object will store a pointer to the array, which means the array needs to exist for at least as long as this object.

Python
Not present.
Parameters
beginthe beginning of the C-style array (that is, a pointer to the first element).
enda pointer past the end of the C-style array (that is, a pointer immediately after the last element).

◆ ListView() [3/3]

template<typename Element >
regina::ListView< Element * >::ListView ( const ListView< Element * > &  )
default

Creates a new copy of the given list view.

Member Function Documentation

◆ __iter__()

template<typename Element >
auto regina::ListView< Element * >::__iter__ ( ) const

Returns a Python iterator over the elements of this list.

C++
Not present. For C++ users, ListView provides the usual begin() and end() functions instead. In particular, you can iterate over the elements of this list in the usual way using a range-based for loop.
Returns
an iterator over the elements of this list.

◆ back()

template<class Element >
ListView< Element * >::const_reference regina::ListView< Element * >::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 Element >
ListView< Element * >::const_iterator regina::ListView< Element * >::begin
inline

Returns a C++ iterator pointing to the first element of this list.

Python
Not present. For Python users, ListView implements the Python iterable interface. You can iterate over the elements of this list in the same way that you would iterate over any native Python container.
Returns
an iterator at the beginning of this list.

◆ empty()

template<class Element >
bool regina::ListView< Element * >::empty
inline

Determines if this list is empty.

Returns
true if and only if this list is empty.

◆ end()

template<class Element >
ListView< Element * >::const_iterator regina::ListView< Element * >::end
inline

Returns a C++ iterator pointing beyond the last element of this list.

Python
Not present. For Python users, ListView implements the Python iterable interface. You can iterate over the elements of this list in the same way that you would iterate over any native Python container.
Returns
an iterator beyond the end of this list.

◆ front()

template<class Element >
ListView< Element * >::const_reference regina::ListView< Element * >::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 Element >
bool regina::ListView< Element * >::operator!= ( const ListView< Element * > &  other) const
inline

Determines whether this and the given list view are accessing different underlying C-style arrays.

To be considered the same array, the two arrays must have the same location in memory (i.e., the pointers that define the C-style arrays must be equal), and the two arrays must have the same length. In particular, it is not enough for the two arrays just to have identical contents.

Parameters
otherthe list view to compare with this.
Returns
true if and only if this and the given list use different underlying arrays.

◆ operator=()

template<typename Element >
ListView & regina::ListView< Element * >::operator= ( const ListView< Element * > &  )
default

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

Returns
a reference to this list view.

◆ operator==()

template<class Element >
bool regina::ListView< Element * >::operator== ( const ListView< Element * > &  other) const
inline

Determines whether this and the given list view are accessing the same underlying C-style array.

To be considered the same array, the two arrays must have the same location in memory (i.e., the pointers that define the C-style arrays must be equal), and the two arrays must have the same length. In particular, it is not enough for the two arrays just to have identical contents.

Parameters
otherthe list view to compare with this.
Returns
true if and only if this and the given list use the same underlying array.

◆ operator[]()

template<class Element >
ListView< Element * >::const_reference regina::ListView< Element * >::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 Element >
ListView< Element * >::size_type regina::ListView< Element * >::size
inline

Returns the number of elements in this list.

Python
This is also used to implement the Python special method len().
Returns
the number of elements.

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

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