A lightweight object that can be used for iteration and random access to all elements of a given list.
More...
|
using | value_type = typename Container::value_type |
| The type of element that is stored in this list.
|
|
using | size_type = typename Container::size_type |
| The type used for indexing into this list.
|
|
using | reference = typename Container::const_reference |
| A reference to a list element.
|
|
using | const_reference = typename Container::const_reference |
| A reference to a list element.
|
|
using | iterator = typename Container::const_iterator |
| The iterator type for this list view.
|
|
using | const_iterator = typename Container::const_iterator |
| The iterator type for this list view.
|
|
|
| ListView (const Container &list) |
| Returns a view for the given list.
|
|
| ListView (const ListView &)=default |
| Creates a new copy of the given list view.
|
|
ListView & | operator= (const ListView &)=default |
| Sets this to be a copy of the given list view.
|
|
bool | empty () const |
| Determines if this list is empty.
|
|
size_type | size () const |
| Returns the number of elements in this list.
|
|
const_reference | operator[] (size_type index) const |
| Returns the requested element of this list.
|
|
const_reference | front () const |
| Returns the first element of this list.
|
|
const_reference | back () const |
| Returns the last element of this list.
|
|
const_iterator | begin () const |
| Returns a C++ iterator pointing to the first element of this list.
|
|
const_iterator | end () const |
| Returns a C++ iterator pointing beyond the last element of this list.
|
|
auto | __iter__ () const |
| Returns a Python iterator over the elements of this list.
|
|
bool | operator== (const ListView &other) const |
| Determines whether this and the given list view are accessing the same underlying container.
|
|
bool | operator!= (const ListView &other) const |
| Determines whether this and the given list view are accessing different underlying containers.
|
|
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.
This access is read-only, in the sense that both the list itself and the list elements are read-only. (Of course, if the list elements are non-const pointers then this means that the pointers cannot be reassigned to point to different objects, but the objects they point to can still be modified.)
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 several different ways of representing a list:
- If your list is stored using a container class (e.g., std::vector or regina::MarkedVector), then you can create a ListView directly from the container using the syntax
ListView(container)
. This uses the generic ListView<Container> class template. There is no need to explicitly specify the ListView template arguments.
- If your list is stored using a C-style array whose size is not known at compile-time, you can create a ListView using either the syntax
ListView(array, size)
or ListView(begin, end)
. Here array is a pointer to the beginning of the array, and begin and end behave as an iterator pair (so 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.
- If your list is stored using a C-style array whose size is fixed at compile-time (i.e., the type is
Element[n]
for some constant n), you can create a ListView using the syntax ListView(array)
. Once 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.
- Python
- The ListView classes are deliberately difficult to access: they live within their own private Python namespaces, and are all give the same class name (ListView). You would typically only interact with a ListView when it is returned from a function (e.g.,
Link.crossings()
), and in most cases you would simply iterate over this resulting ListView without ever knowing its exact type.
- Template Parameters
-
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. |