Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
util-foreach.hpp File Reference

Perform operations "for each element" of a collection. More...

Go to the source code of this file.

Description

Perform operations "for each element" of a collection.

This header defines various flavours of these active iteration functions, which all take a functor and invoke it in some way over the collection's elements.

  • basic constructs
    • for_each
    • and_all (all quantisation)
    • has_any (existence quantisation)
  • kinds of collection
    • STL collections and anything which has an iterator, begin() and end()
    • "Lumiera Forward Iterator" instance to yield all the elements of the collection
  • support for on-the-fly binding up to 4 arguments of the functor
Warning
in the standard case (STL container) the collection to operate on is taken by const& – but the const is stripped silently.

Thus, within the iteration, the function passed in can modify the original collection. If you pass in a ref to a temporary, the compiler won't complain. Moreover, several kinds of wrappers are also stripped silently, including reference_wrapper, shared_ptr and lumiera::P. The rationale for this non-standard behaviour is to allow convenient writing of in-line iteration, where even the collection to iterate is yielded by function call.

See also
util-foreach-test.cpp

Definition in file util-foreach.hpp.

#include "lib/util.hpp"
#include "lib/meta/trait.hpp"
#include <functional>
#include <algorithm>

Namespaces

namespace  util
 

Functions

template<typename IT , typename FUN >
bool and_all (IT i, IT end, FUN predicate)
 All quantification: check if all elements of a collection satisfy the given predicate.
 
template<typename IT , typename FUN >
bool has_any (IT i, IT end, FUN predicate)
 Existential quantification: check if any element of a collection satisfies the given predicate.
 
template<typename Container , typename FUN >
disable_if< can_IterForEach< Container >, FUN > for_each (Container const &coll, FUN doIt)
 operate on all elements of a STL container.
 
template<typename IT , typename FUN >
enable_if< can_IterForEach< IT >, FUN > for_each (IT const &ii, FUN doIt)
 operate on a Lumiera Forward Iterator until exhaustion.
 
template<typename Container , typename FUN >
enable_if< can_STL_ForEach< Container >, bool > and_all (Container const &coll, FUN predicate)
 
template<typename IT , typename FUN >
enable_if< can_IterForEach< IT >, bool > and_all (IT const &ii, FUN predicate)
 
template<typename Container , typename FUN >
enable_if< can_STL_ForEach< Container >, bool > has_any (Container const &coll, FUN predicate)
 
template<typename IT , typename FUN >
enable_if< can_IterForEach< IT >, bool > has_any (IT const &ii, FUN predicate)
 
template<typename CON , typename FUN , typename P1 , typename... ARGS>
void for_each (CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
 Accept binding for arbitrary function arguments.
 
template<typename CON , typename FUN , typename P1 , typename... ARGS>
bool and_all (CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
 Accept binding for arbitrary function arguments.
 
template<typename CON , typename FUN , typename P1 , typename... ARGS>
bool has_any (CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
 Accept binding for arbitrary function arguments.