ForEachIterator< ITERATOR, SUPER > Class Template Reference

#include <foreach.h>

Inheritance diagram for ForEachIterator< ITERATOR, SUPER >:

Detailed Description

template<typename ITERATOR, typename SUPER = EmptyClass>
class maxon::ForEachIterator< ITERATOR, SUPER >

ForEachIterator is a helper template for the implementation of a foreach iterator (see maxon::Iterable). You can use it as public base class for your foreach iterator class with the template argument ITERATOR being your class as in

class MyForEachIterator : public ForEachIterator<MyForEachIterator>
{
public:
void operator ++();
explicit operator Bool() const;
String& operator *() const;
String* operator ->() const;
};
Definition: c4d_string.h:41
MAXON_ATTRIBUTE_FORCE_INLINE ForEachIterator(ARGS &&... args)
Definition: foreach.h:248
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:195
Col3< typename MultiplicativePromotion< T, S, STD_IS_REPLACEMENT(scalar, S)>::type, 1 > operator*(S s, const Col3< T, STR > &v)
Multiplies each vector component by a scalar.
Definition: col.h:463
PORT_DIR & operator++(PORT_DIR &dir)
Definition: graph_basics.h:44

This relieves you from the need to declare a IsForEachIterator type alias, and it adds some functions such as ToString and Contains. However note that these functions are non-const, i.e., they use the current iterator for the iteration so that it will point to another iteration value after function completion.

See also
maxon::Iterable
$ref foreach
Template Parameters
ITERATORThe class which implements the foreach protocol, ForEachIterator should be its base class.
SUPERThis is used as base class of ForEachIterator.

Classes

class  Wrapper
 

Public Types

using IsForEachIterator = std::true_type
 

Public Member Functions

template<typename... ARGS>
MAXON_ATTRIBUTE_FORCE_INLINE ForEachIterator (ARGS &&... args)
 
String ToString (const FormatStatement *formatStatement=nullptr)
 
template<typename T >
ITERATOR & Find (const T &v)
 
template<typename T >
Int FindIndex (const T &v)
 
template<typename T >
MAXON_ATTRIBUTE_FORCE_INLINE Bool Contains (const T &v)
 
MAXON_ATTRIBUTE_FORCE_INLINE Wrapper begin ()
 

Static Public Member Functions

static MAXON_ATTRIBUTE_FORCE_INLINE PRIVATE_MAXON_RBF_SENTINEL (Wrapper) end()
 

Member Typedef Documentation

◆ IsForEachIterator

using IsForEachIterator = std::true_type

This marker indicates that this ForEachIterator supports the foreach protocol (see Iterable).

Constructor & Destructor Documentation

◆ ForEachIterator()

MAXON_ATTRIBUTE_FORCE_INLINE ForEachIterator ( ARGS &&...  args)
explicit

Member Function Documentation

◆ Find()

ITERATOR& Find ( const T &  v)

Iterates over this foreach iterator until an iteration value is found which equals v. The function advances this iterator. Example:

MyForEachIterator it = ...;
while (it.Find(value))
{
... do something with *it (which equals value) ...;
}
PyObject * value
Definition: abstract.h:715
Parameters
[in]vValue for comparison.
Returns
This iterator, either pointing to an iteration value which equals v, or to the end.

◆ FindIndex()

Int FindIndex ( const T &  v)

Iterates over this foreach iterator until an iteration value is found which equals v, and returns the number of needed iterations or a negative value if v couldn't be found.

Parameters
[in]vValue for comparison.
Returns
Number of iterations to reach an iteration value which equals v, or a negative value if no such value could be found.
Warning
This is a non-const function which uses this iterator for the iteration.

◆ Contains()

MAXON_ATTRIBUTE_FORCE_INLINE Bool Contains ( const T &  v)

Iterates over this foreach iterator until an iteration value is found which equals v and returns true on success, or false if v couldn't be found.

Parameters
[in]vValue for comparison.
Returns
True if v could be found as iteration value of this iterator.
Warning
This is a non-const function which uses this iterator for the iteration.

◆ begin()

◆ PRIVATE_MAXON_RBF_SENTINEL()

static MAXON_ATTRIBUTE_FORCE_INLINE PRIVATE_MAXON_RBF_SENTINEL ( Wrapper  )
static