ImpactX
Functions
pyImpactX Namespace Reference

Functions

template<typename T_Iterator >
T_Iterator & iterator_next (T_Iterator &it)
 

Function Documentation

◆ iterator_next()

template<typename T_Iterator >
T_Iterator& pyImpactX::iterator_next ( T_Iterator &  it)

This is a helper function for the C++ equivalent of void operator++()

In Python, iterators always are called with next, even for the first access. This means we need to handle the first iterator element explicitly, otherwise we will jump directly to the 2nd element. We do this the same way as pybind11 does this, via a little state: https://github.com/AMReX-Codes/pyamrex/pull/50 https://github.com/pybind/pybind11/blob/v2.10.0/include/pybind11/pybind11.h#L2269-L2282

To avoid unnecessary (and expensive) copies, remember to only call this helper always with py::return_value_policy::reference_internal!

Template Parameters
T_IteratorThis is usally MFIter or Par(Const)Iter or derived classes
Parameters
itthe current iterator
Returns
the updated iterator