|
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.
|
|
iterator & | operator= (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.
|
|
iterator & | operator++ () |
| The preincrement operator.
|
|
iterator | operator++ (int) |
| The postincrement operator.
|
|
Perm< n > | __next__ () |
| Returns the current permutation and increments this iterator.
|
|
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__()
.