#include <foreach.h>
AutoIterator implements a foreach iterator based on two normal iterators. one for the current position and a constant one for the end. This simplifies cases like iterating over a whole array or list. Typical usage is:
You can specify the current and end iterator explicitly as in
In addition to the basic foreach protocol, AutoIterator also supports the iterator arithmetic of the underlying iterator, but only in forward direction:
C | Either a collection class with a valid Iterator, or the Iterator class itself. |
Public Types | |
using | Iterator = typename GetIteratorType< C >::type |
using | CollectionType = typename GetCollectionType< C >::type |
using | ValueType = decltype(*std::declval< Iterator >()) |
template<typename SUPER > | |
using | ResultFunctions = ResultIteratorFunctions< SUPER > |
using | InvConstAutoIterator = AutoIterator< typename ConstIf< typename std::remove_const< C >::type, !STD_IS_REPLACEMENT(const, C)>::type > |
Public Types inherited from ForEachIterator< AutoIterator< C > > | |
using | IsForEachIterator = std::true_type |
Protected Member Functions | |
MAXON_ATTRIBUTE_FORCE_INLINE | AutoIterator (const Iterator &s, const Iterator &e, Bool removed) |
Protected Attributes | |
Iterator | _it |
Iterator | _end |
Additional Inherited Members | |
Static Public Member Functions inherited from ForEachIterator< AutoIterator< C > > | |
static MAXON_ATTRIBUTE_FORCE_INLINE | PRIVATE_MAXON_RBF_SENTINEL (Wrapper) end() |
using Iterator = typename GetIteratorType<C>::type |
using CollectionType = typename GetCollectionType<C>::type |
using ResultFunctions = ResultIteratorFunctions<SUPER> |
using InvConstAutoIterator = AutoIterator<typename ConstIf<typename std::remove_const<C>::type, !STD_IS_REPLACEMENT(const, C)>::type> |
|
explicit |
Use this constructor if you want to iterate over all elements of a collection. Please note that the end iterator of the AutoIterator is a constant. When you modify an array (via Insert(), Append() or Erase()) the value of its End() iterator will most likely change and trying to iterate over such an array with an AutoIterator while modifying it would crash. To safely erase the current element, use iterator.Erase(collection)
.
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator | ( | const Iterator & | s, |
const Iterator & | e | ||
) |
use this constructor if you want to iterate from s until e (excluding e)
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator | ( | CollectionType & | collection, |
Int | s, | ||
Int | e = InvalidArrayIndex |
||
) |
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator | ( | AutoIterator< C > && | src | ) |
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator | ( | const AutoIterator< C > & | src | ) |
|
protected |
MAXON_OPERATOR_MOVE_ASSIGNMENT | ( | AutoIterator< C > | ) |
MAXON_OPERATOR_COPY_ASSIGNMENT | ( | AutoIterator< C > | ) |
|
explicit |
Operator that returns false when the end of the array has been reached. explicit operator bool() would be ambiguous because it can be used for integer arithmetic. For C++11 we use explicit bool to avoid that implicit conversion, for older compilers void* is returned because you can't do arithmetic with it.
MAXON_ATTRIBUTE_FORCE_INLINE ValueType operator* | ( | ) | const |
MAXON_ATTRIBUTE_FORCE_INLINE std::remove_reference<ValueType>::type* operator-> | ( | ) | const |
MAXON_ATTRIBUTE_FORCE_INLINE Bool operator== | ( | const AutoIterator< C > & | b | ) | const |
MAXON_ATTRIBUTE_FORCE_INLINE Bool operator< | ( | const AutoIterator< C > & | b | ) | const |
MAXON_OPERATOR_COMPARISON | ( | AutoIterator< C > | ) |
MAXON_ATTRIBUTE_FORCE_INLINE Bool operator== | ( | const InvConstAutoIterator< C > & | b | ) | const |
MAXON_ATTRIBUTE_FORCE_INLINE Bool operator< | ( | const InvConstAutoIterator< C > & | b | ) | const |
MAXON_OPERATOR_COMPARISON | ( | InvConstAutoIterator< C > | ) |
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator& operator++ | ( | ) |
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator operator++ | ( | int | ) |
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator& operator+= | ( | Int | i | ) |
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator operator+ | ( | Int | i | ) | const |
MAXON_ATTRIBUTE_FORCE_INLINE Int operator- | ( | const AutoIterator< C > & | b | ) | const |
MAXON_ATTRIBUTE_FORCE_INLINE Int operator- | ( | const Iterator & | b | ) | const |
MAXON_ATTRIBUTE_FORCE_INLINE void Erase | ( | CollectionType & | collection | ) |
Removes the current iteration value from the underlying collection. The AutoIterator will point to the element behind the removed one afterwards. Example:
[in] | collection | The collection to remove the value from. This has to be the collection which was used to construct this AutoIterator. |
MAXON_ATTRIBUTE_FORCE_INLINE operator Iterator & | ( | ) |
MAXON_ATTRIBUTE_FORCE_INLINE Iterator& GetIterator | ( | ) |
|
protected |
|
protected |