STXXL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::for_each_m (mutating)
Author
Roman Dementiev (2006)

stxxl::for_each_m is a mutating version of stxxl::for_each, i.e. the restriction that Unary Function functor can not apply only constant operations through its argument does not exist.

Prototype

template < typename ExtIterator, typename UnaryFunction >
UnaryFunction for_each_m ( ExtIterator first,
ExtIterator last,
UnaryFunction functor,
int nbuffers
)

Description

stxxl::for_each_m applies the function object functor to each element in the range [first, last); functor's return value, if any, is ignored. Applications are performed in forward order, i.e. from first to last. stxxl::for_each_m returns the function object after it has been applied to each element. To overlap I/O and computation nbuffers are used (a value at least 2D is recommended). The size of the buffers is derived from the container that is pointed by the iterators.

Remarks
The implementation exploits STXXL buffered streams (computation and I/O overlapped)
Parameters
beginobject of model of ext_random_access_iterator concept
endobject of model of ext_random_access_iterator concept
functorobject of model of std::UnaryFunction concept
nbuffersnumber of buffers (blocks) for internal use (should be at least 2*D )
Returns
function object functor after it has been applied to the each element of the given range
Warning
nested stxxl::for_each_m are not supported

Requirements on types

  • ExtIterator is a model of External Random Access Iterator.
  • UnaryFunction is a model of STL Unary Function.
  • 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 $ 2N/DB $ I/Os (read and write).

Example

struct AddX
{
int x;
AddX(int x_): x(x_) {}
void operator() (int & val)
{ val += x; }
};
int main()
{
vector_type A(N);
// fill A with some values ...
// Add 5 to each value in the vector
stxxl::for_each_m(A.begin(), A.end(), AddX(5));
}