Iterable defines some static helper functions to construct foreach iterators. A foreach iterator supports the foreach-protocol consisting of the following class members:
- A member
type alias std::true_type IsForEachIterator;
indicates that the class defines a foreach iterator.
- explicit operator Bool() checks if the iterator object has a valid current value. When this returns false for the first time, the iteration terminates.
- operator ++() advances the iterator object.
- The function
operator *() const
to return the current iteration value.
- A move or copy constructor for the iterator is needed for some operations of Iterable.
Given this protocol, an iteration over all values is done by
for (MyForEachIterator it = ...; it; ++it)
{
MyValueType&
value = *it;
...
}
PyObject * value
Definition: abstract.h:715
The foreach iterators returned by Iterable functions support range-based for loops:
{
...
}
PyObject PyObject * v
Definition: abstract.h:297
static SingletonForEachIterator< T > GetSingleton(T &&value)
Definition: foreach.h:1399
static ConcatForEachIterator< T, typename IteratorType< I1 && >::type, typename IteratorType< I2 && >::type > Concat(I1 &&it1, I2 &&it2)
Definition: foreach.h:1425
PyObject * x
Definition: bytesobject.h:38
- See also
- $ref foreach
|
template<typename T , Int N> |
static AutoIterator< T[N]> | Get (T(&array)[N]) |
|
template<typename I > |
static SFINAEHelper< AutoIterator< typename std::remove_reference< I >::type >, typename std::remove_reference< I >::type::ConstIterator >::type | Get (I &&iterable) |
|
template<typename I > |
static SFINAEHelper< I &&, typename std::remove_reference< I >::type::IsForEachIterator >::type | Get (I &&iterator) |
|
template<typename ITERABLE > |
static maxon::details::ReverseIterable< ITERABLE > | Reverse (ITERABLE &&iterable) |
|
template<typename COLLECTION > |
static MAXON_ATTRIBUTE_FORCE_INLINE maxon::EraseIterator< COLLECTION, false > | EraseIterator (COLLECTION &c) |
|
template<typename COLLECTION > |
static MAXON_ATTRIBUTE_FORCE_INLINE maxon::EraseIterator< COLLECTION, true > | SwapEraseIterator (COLLECTION &c) |
|
template<typename I > |
static IndexForEachIterator< typename IteratorType< I && >::type > | IndexIterator (I &&it) |
|
template<typename T > |
static SingletonForEachIterator< T > | GetSingleton (T &&value) |
|
template<typename T = void, typename I1 , typename I2 > |
static ConcatForEachIterator< T, typename IteratorType< I1 && >::type, typename IteratorType< I2 && >::type > | Concat (I1 &&it1, I2 &&it2) |
|
template<typename T = void, typename I1 , typename I2 > |
static ConditionalForEachIterator< T, typename IteratorType< I1 && >::type, typename IteratorType< I2 && >::type > | Conditional (Bool select, I1 &&it1, I2 &&it2) |
|
template<typename I , typename MAP > |
static MapForEachIterator< MAP, typename IteratorType< I && >::type > | Map (I &&values, MAP &&fn) |
|
template<typename I , typename FILTER > |
static FilterForEachIterator< FILTER, typename IteratorType< I && >::type > | Filter (I &&values, FILTER &&filter) |
|
template<typename I1 , typename I2 > |
static ZipForEachIterator< typename IteratorType< I1 && >::type, typename IteratorType< I2 && >::type > | Zip (I1 &&it1, I2 &&it2) |
|
template<typename I > |
static Bool | Any (I &&iterable) |
|
template<typename I , typename MAP > |
static Bool | Any (I &&iterable, MAP &&map) |
|
template<typename I > |
static Bool | All (I &&iterable) |
|
template<typename I , typename MAP > |
static Bool | All (I &&iterable, MAP &&map) |
|
Returns a foreach iterator which iterates over either first
or second
, depending on select
. If select
is true
, the iterator will iterate over all values of first
(second
won't be used at all), and vice versa if select
is false
. Example:
{
...
}
static ConditionalForEachIterator< T, typename IteratorType< I1 && >::type, typename IteratorType< I2 && >::type > Conditional(Bool select, I1 &&it1, I2 &&it2)
Definition: foreach.h:1452
The result type of the returned iterator will be the common type of the value types of the two input iterators if you don't specify the T
parameter. If such a common type doesn't exist, you have to specify the T
parameter.
- Parameters
-
[in] | select | If true , iterate over first , otherwise over second . |
[in] | it1 | The first iterator, may be any iterable object. |
[in] | it2 | The second iterator, may be any iterable object. |
- Template Parameters
-
T | The value type of the result iterator. |
I1 | Type of the first iterator. |
I2 | Type of the second iterator. |
- Returns
- Conditional foreach iterator iterating over
first
if select
is true
, over second
otherwise.
Returns a foreach iterator which maps each of the values of the underlying iterator values
by the given function fn
. I.e., if the original values are v1, v2, ..., the returned iterator will yield the values fn(v1), fn(v2), ...
For example, to compute the sum of the squared values of an array using GetSum, you write
BaseArray<Int> array;
...
static MapForEachIterator< MAP, typename IteratorType< I && >::type > Map(I &&values, MAP &&fn)
Definition: foreach.h:1475
maxon::Int Int
Definition: ge_sys_math.h:60
MAXON_ATTRIBUTE_FORCE_INLINE std::remove_reference< ITERABLETYPE >::type::ValueType GetSum(ITERABLETYPE &&array)
Returns the sum of all elements.
Definition: lib_math.h:287
- Parameters
-
[in] | values | The values to iterate over, may be any iterable object. |
[in] | fn | The function which maps each original value to the target value of the returned iterator. |
- Template Parameters
-
I | Type of the values. |
MAP | Type of the mapping function. |
- Returns
- Foreach iterator iterating over
values
, mapped by fn
.