- Author
- Roman Dementiev (2006)
The semantics of the algorithm is equivalent to the STL std::for_each.
Prototype
template < typename ExtIterator, typename UnaryFunction >
UnaryFunction for_each ( ExtIterator first,
ExtIterator last,
UnaryFunction functor,
int_type nbuffers
)
Description
Requirements on types
ExtIterator
is a model of External Random Access Iterator.
UnaryFunction
is a model of STL Unary Function.
UnaryFunction
does not apply any non-constant operations through its argument.
ExtIterator's
value type is convertible to UnaryFunction's
argument type.
Preconditions
[first, last) is a valid range.
Complexity
- Internal work is linear.
- External work: close to
I/Os (read-only).
Example
template<class T>
struct print : public unary_function<T, void>
{
print(ostream& out) : os(out), count(0) {}
void operator() (T x) { os << x << ' '; ++count; }
ostream& os;
int count;
};
typedef stxxl::VECTOR_GENERATOR<int>::result vector_type;
int main()
{
vector_type A(N);
print<int> P = stxxl::for_each(A.begin(), A.end(), print<int>(cout));
cout << endl << P.count << " objects printed." << endl;
}