Delen via


parallel_for_each Function

parallel_for_each applies a specified function to each element within a range, in parallel. It is semantically equivalent to the for_each function in the std namespace, except that iteration over the elements is performed in parallel, and the order of iteration is unspecified. The argument _Func must support a function call operator of the form operator()(T) where the parameter T is the item type of the container being iterated over.

template <
   typename _Iterator,
   typename _Function
>
void parallel_for_each(
   _Iterator_First,
   _Iterator_Last,
   const _Function& _Func
);

template <
   typename _Iterator,
   typename _Function,
   typename _Partitioner
>
void parallel_for_each(
   _Iterator_First,
   _Iterator_Last,
   const _Function& _Func,
   _Partitioner&& _Part
);

Parameters

  • _Iterator
    The type of the iterator being used to iterate over the container.

  • _Function
    The type of the function that will be applied to each element within the range.

  • _Partitioner

  • _First
    An iterator addressing the position of the first element to be included in parallel iteration.

  • _Last
    An iterator addressing the position one past the final element to be included in parallel iteration.

  • _Func
    A user-defined function object that is applied to each element in the range.

  • _Part
    A reference to the partitioner object. The argument can be one of constauto_partitioner&, conststatic_partitioner&, constsimple_partitioner& or affinity_partitioner& If an affinity_partitioner object is used, the reference must be a non-const l-value reference, so that the algorithm can store state for future loops to re-use.

Remarks

auto_partitioner will be used for the overload without an explicit partitioner.

For iterators that do not support random access, only auto_partitioner is supported.

For more information, see Parallel Algorithms.

Requirements

Header: ppl.h

Namespace: concurrency

See Also

Reference

concurrency Namespace