Regina 7.3.1 Calculation Engine
regina::ChildIterator< const_ > Class Template Reference

A forward iterator for iterating through all immediate children of a given packet. More...

#include <packet/packet.h>

Public Types

using packet_type = std::conditional_t<const_, const Packet, Packet>
 Indicates what the iterator points to.
 

Public Member Functions

 ChildIterator ()=default
 Creates a past-the-end iterator.
 
 ChildIterator (const ChildIterator &)=default
 Creates a new copy of the given iterator.
 
 ChildIterator (std::shared_ptr< packet_type > current)
 Creates a new iterator pointing to the given child packet.
 
ChildIteratoroperator= (const ChildIterator &)=default
 Sets this to be a copy of the given iterator.
 
bool operator== (const ChildIterator &rhs) const
 Tests whether this and the given iterator are equal.
 
bool operator!= (const ChildIterator &rhs) const
 Tests whether this and the given iterator are different.
 
ChildIteratoroperator++ ()
 Preincrement operator.
 
ChildIterator operator++ (int)
 Postincrement operator.
 
auto __next__ ()
 Returns the current child packet and increments this iterator.
 
packet_typeoperator* () const
 Returns the packet that this iterator is currently pointing to.
 
 operator bool () const
 Identifies whether this iterator is dereferencable.
 

Detailed Description

template<bool const_>
class regina::ChildIterator< const_ >

A forward iterator for iterating through all immediate children of a given packet.

Each iterator will hold a std::shared_ptr to the packet whose children it is iterating over. This guarantees that the packet will not be destroyed mid-iteration, but it also means that you must ensure that you dispose of your iterators once you are finished with them.

As of Regina 7.3.1, this class no longer provides the iterator type aliases value_type, iterator_category, difference_type, pointer and reference. Instead you can access these through std::iterator_traits.

Template Parameters
const_Indicates whether this iterator should offer const or non-const access to the child packets.
Python
Instead of the C++ interface described here, in Python the classes PacketChildren and ChildIterator together implement the Python iterable/iterator interface. The class PacketChildren has just the single function __iter__(), which returns a ChildIterator; then ChildIterator implements __next__(), which either returns the next child packet in the iteration or else throws a StopException if there are no more children to return. All iteration in Python is non-const (i.e., Python exclusively uses the classes where const_ is false).

Member Typedef Documentation

◆ packet_type

template<bool const_>
using regina::ChildIterator< const_ >::packet_type = std::conditional_t<const_, const Packet, Packet>

Indicates what the iterator points to.

This is either Packet or const Packet, according to the template argument const_.

Constructor & Destructor Documentation

◆ ChildIterator() [1/3]

template<bool const_>
regina::ChildIterator< const_ >::ChildIterator ( )
default

Creates a past-the-end iterator.

Python
Not present. The only way to create a ChildIterator is via Packet::children().

◆ ChildIterator() [2/3]

template<bool const_>
regina::ChildIterator< const_ >::ChildIterator ( const ChildIterator< const_ > & )
default

Creates a new copy of the given iterator.

Python
Not present. The only way to create a ChildIterator is via Packet::children().

◆ ChildIterator() [3/3]

template<bool const_>
regina::ChildIterator< const_ >::ChildIterator ( std::shared_ptr< packet_type > current)
inline

Creates a new iterator pointing to the given child packet.

Python
Not present. The only way to create a ChildIterator is via Packet::children().
Parameters
currentthe child packet that the new iterator should point to, or null if the new iterator should be past-the-end.

Member Function Documentation

◆ __next__()

template<bool const_>
auto regina::ChildIterator< const_ >::__next__ ( )

Returns the current child packet and increments this iterator.

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

◆ operator bool()

template<bool const_>
regina::ChildIterator< const_ >::operator bool ( ) const
inline

Identifies whether this iterator is dereferencable.

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

◆ operator!=()

template<bool const_>
bool regina::ChildIterator< const_ >::operator!= ( const ChildIterator< const_ > & rhs) const
inline

Tests whether this and the given iterator are different.

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

◆ operator*()

template<bool const_>
ChildIterator< const_ >::packet_type & regina::ChildIterator< const_ >::operator* ( ) const
inline

Returns the packet that this iterator is currently pointing to.

Precondition
This iterator is dereferenceable (i.e., it is not past-the-end).
Python
Not present. For Python users, ChildIterator implements the Python iterator interface instead. See next() for details.
Returns
the current packet.

◆ operator++() [1/2]

template<bool const_>
ChildIterator< const_ > & regina::ChildIterator< const_ >::operator++ ( )
inline

Preincrement operator.

Precondition
This iterator is dereferenceable (i.e., it is not past-the-end).
Python
Not present. For Python users, ChildIterator implements the Python iterator interface instead. See next() for details.
Returns
a reference to this iterator.

◆ operator++() [2/2]

template<bool const_>
ChildIterator< const_ > regina::ChildIterator< const_ >::operator++ ( int )
inline

Postincrement operator.

Precondition
This iterator is dereferenceable (i.e., it is not past-the-end).
Python
Not present. For Python users, ChildIterator implements the Python iterator interface instead. See next() for details.
Returns
a a copy of this iterator before it was incremented.

◆ operator=()

template<bool const_>
ChildIterator & regina::ChildIterator< const_ >::operator= ( const ChildIterator< const_ > & )
default

Sets this to be a copy of the given iterator.

Returns
a reference to this iterator.

◆ operator==()

template<bool const_>
bool regina::ChildIterator< const_ >::operator== ( const ChildIterator< const_ > & rhs) const
inline

Tests whether this and the given iterator are equal.

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

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

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