Regina 7.4 Calculation Engine
regina::PermSn< n, order, codeType >::iterator Class Reference

An iterator over all permutations of n objects. More...

#include <maths/permsn.h>

Public Types

using value_type = Perm<n>
 Indicates what type the iterator points to.
 
using iterator_category = std::forward_iterator_tag
 Declares the type of this iterator.
 
using difference_type = typename Perm<n>::Index
 The type obtained by subtracting iterators.
 
using pointer = const value_type*
 A pointer to value_type.
 
using reference = Perm<n>
 The type returned by the dereference operator, which for this iterator type is by value.
 

Public Member Functions

constexpr iterator ()
 Creates a begin iterator.
 
constexpr iterator (bool valid)
 Creates either a begin or end iterator.
 
constexpr iterator (const iterator &)=default
 Creates a copy of the given iterator.
 
iteratoroperator= (const iterator &)=default
 Makes this a copy of the given iterator.
 
constexpr bool operator== (const iterator &) const =default
 Compares this with the given iterator for equality.
 
constexpr operator bool () const
 Identifies whether this iterator is dereferenceable.
 
constexpr Perm< n > operator* () const
 Returns the permutation that this iterator is currently pointing to.
 
iteratoroperator++ ()
 The preincrement operator.
 
iterator operator++ (int)
 The postincrement operator.
 
Perm< n > __next__ ()
 Returns the current permutation and increments this iterator.
 

Detailed Description

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
class regina::PermSn< n, order, codeType >::iterator

An iterator over all permutations of n objects.

See the PermSn class notes for further details on how iteration works. In particular:

  • For smaller permutations (n ≤ 7), these iterators are random-access, and all of the expected operations are fast constant time.
  • For larger permutations (n ≥ 8), these are forward iterators only, and a single forward step takes time linear in n.

Unlike most iterator types, the dereference operator for this iterator type returns by value, not by reference. This is because the individual permutations are generated, not stored.

For most iterator classes, Regina now uses specialisations of std::iterator_traits to provide access to their associated types (e.g., value_type). However, this is not possible for PermSn::iterator since PermSn is templated. Therefore, for PermSn::iterator, we continue to provide these associated types directly as class members.

Both iterator and const_iterator are the same type, since PermSn only offers read-only access to its permutations.

The full interface for the iterator type is not documented here, since it changes according to both n and your programming language:

  • In C++, this class implements the full interface for either a random access iterator (n ≤ 7) or a forward iterator (n ≥ 8). Using Perm<n>::Sn as an example, you would typically access iterators either via Perm<n>::Sn.begin() and Perm<n>::Sn.end(), or by using a range-based for loop over Perm<n>::Sn.
  • In Python, this class and PermSn together implement the expected interface for Python iterators. Using Perm4.Sn as an example, you would typically create and use iterators by iterating over Perm4.Sn, which internally uses PermSn4_Sign.__iter__() and PermSn4_Sign.iterator.__next__().

Member Typedef Documentation

◆ difference_type

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
using regina::PermSn< n, order, codeType >::iterator::difference_type = typename Perm<n>::Index

The type obtained by subtracting iterators.

◆ iterator_category

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
using regina::PermSn< n, order, codeType >::iterator::iterator_category = std::forward_iterator_tag

Declares the type of this iterator.

For n ≤ 7 this will be std::random_access_iterator_tag, and for n ≥ 8 this will be std::forward_iterator_tag.

◆ pointer

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
using regina::PermSn< n, order, codeType >::iterator::pointer = const value_type*

A pointer to value_type.

◆ reference

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
using regina::PermSn< n, order, codeType >::iterator::reference = Perm<n>

The type returned by the dereference operator, which for this iterator type is by value.

This is because permutations are generated, not stored.

◆ value_type

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
using regina::PermSn< n, order, codeType >::iterator::value_type = Perm<n>

Indicates what type the iterator points to.

Constructor & Destructor Documentation

◆ iterator() [1/3]

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
regina::PermSn< n, order, codeType >::iterator::iterator ( )
inlineconstexpr

Creates a begin iterator.

This iterator will point to the identity permutation. So, for example, if you are iterating over Perm<n>::Sn, then this iterator will be equal to Perm<n>::Sn.begin().

◆ iterator() [2/3]

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
regina::PermSn< n, order, codeType >::iterator::iterator ( bool valid)
inlineconstexpr

Creates either a begin or end iterator.

If no arguments are given or if valid is true, then this iterator will point to the identity permutation. For example, if you are iterating over Perm<n>::Sn, then this iterator will be equal to Perm<n>::Sn.begin().

If valid is false, then this iterator will be past-the-end. For example, if you are iterating over Perm<n>::Sn, then this iterator will be equal to Perm<n>::Sn.end().

Parameters
validtrue if this should be a begin iterator, or false if this should be an end iterator.

◆ iterator() [3/3]

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
regina::PermSn< n, order, codeType >::iterator::iterator ( const iterator & )
constexprdefault

Creates a copy of the given iterator.

Python
Not present. The only way to create an iterator is to iterate over an object such as Perm<n>::Sn or Perm<n>::orderedSn.

Member Function Documentation

◆ __next__()

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
Perm< n > regina::PermSn< n, order, codeType >::iterator::__next__ ( )

Returns the current permutation and increments this iterator.

C++
Not present. For C++ users, this iterator class provides the usual preincrement, postincrement and dereferencing operators (++ and *) instead.
Exceptions
StopIterationThe iterator is already past-the-end when this function is called.
Returns
the permutation that this iterator is pointing to, before the increment takes place.

◆ operator bool()

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
regina::PermSn< n, order, codeType >::iterator::operator bool ( ) const
inlineconstexpr

Identifies whether this iterator is dereferenceable.

Python
Not present. For Python users, this class implements the Python iterator interface instead. See next() for details.
Returns
true if and only if this is dereferenceable (i.e., not past-the-end).

◆ operator*()

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
Perm< n > regina::PermSn< n, order, codeType >::iterator::operator* ( ) const
inlineconstexpr

Returns the permutation that this iterator is currently pointing to.

Precondition
This iterator is dereferenceable (in particular, it is not past-the-end).
Python
Not present. For Python users, this class implements the Python iterator interface instead. See next() for details.
Returns
the corresponding permutation.

◆ operator++() [1/2]

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
iterator & regina::PermSn< n, order, codeType >::iterator::operator++ ( )
inline

The preincrement operator.

Python
Not present. For Python users, this class implements the Python iterator interface instead. See next() for details.
Returns
a reference to this iterator after the increment.

◆ operator++() [2/2]

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
iterator regina::PermSn< n, order, codeType >::iterator::operator++ ( int )
inline

The postincrement operator.

Python
Not present. For Python users, this class implements the Python iterator interface instead. See next() for details.
Returns
a copy of this iterator before the increment took place.

◆ operator=()

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
iterator & regina::PermSn< n, order, codeType >::iterator::operator= ( const iterator & )
default

Makes this a copy of the given iterator.

Returns
a reference to this iterator.

◆ operator==()

template<int n, PermOrder order, PermCodeType codeType = Perm<n>::codeType>
bool regina::PermSn< n, order, codeType >::iterator::operator== ( const iterator & ) const
constexprdefault

Compares this with the given iterator for equality.

To be considered equal, two iterators must both be dereferencable and pointing to the same permutation, or must both be past-the-end.

Returns
true if and only if the two iterators are equal.

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