namespace std {
// non-modifying sequence operations
template<class ExecutionPolicy,
class InputIterator, class Function>
InputIterator for_each(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
Function f);
template<class InputIterator, class Size, class Function>
Function for_each_n(InputIterator first, Size n,
Function f);
template<class ExecutionPolicy,
class InputIterator, class Size, class Function>
InputIterator for_each_n(ExecutionPolicy &&exec,
InputIterator first, Size n,
Function f);
}
Novel non-modifying sequence operations
template<class InputIterator, class Size n, class Function>
Function for_each_n(InputIterator first, InputIterator last,
Function f);
-
Requires:
Function
shall meet the requirements ofMoveConstructible
[Note:Function need not meet the requirements of
CopyConstructible`. -- end note] -
Effects: Applies
f
to the result of dereferencing every iterator in the range[first,first + n)
, starting fromfirst
and proceeding tofirst + n - 1
. [Note: If the type offirst
satisfies the requirements of a mutable iterator,f
may apply nonconstant functions throughthe dereferenced iterator. -- end note] -
Returns:
std::move(f)
. -
Complexity: Applies
f
exactlyn
times. -
Remarks: If
f
returns a result, the result is ignored.
template<class ExecutionPolicy,
class InputIterator, class Function>
InputIterator for_each(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
Function f);
template<class ExecutionPolicy,
class InputIterator, class Size, class Function>
InputIterator for_each_n(ExecutionPolicy &&exec,
InputIterator first, Size n,
Function f);
-
Effects: The first algorithm applies
f
to the result of dereferencing every iterator in the range[first,last)
. The second algorithm appliesf
to the result of dereferencing every iterator in the range[first,first+n)
. The execution of the algorithm is parallelized as determined byexec
. [Note: If the type offirst
satisfies the requirements of a mutable iterator,f
may apply nonconstant functions through the dereferenced iterator. -- end note] -
Returns:
for_each
returnslast
andfor_each_n
returnsfirst + n
for non-negative values ofn
andfirst
for negative values. -
Complexity:
O(last - first)
orO(n)
. -
Remarks: If
f
returns a result, the result is ignored.The signatures shall not participate in overload resolution if
is_execution_policy<ExecutionPolicy>::value
isfalse
.
namespace std {
template<class InputIterator>
typename iterator_traits<InputIterator>::value_type
reduce(InputIterator first, InputIterator last);
template<class ExecutionPolicy,
class InputIterator>
typename iterator_traits<InputIterator>::value_type
reduce(ExecutionPolicy &&exec,
InputIterator first, InputIterator last);
template<class InputIterator, class T>
T reduce(InputIterator first, InputIterator last T init);
template<class ExecutionPolicy,
class InputIterator, class T>
T reduce(ExecutionPolicy &&exec,
InputIterator first, InputIterator last, T init);
template<class InputIterator, class T, class BinaryOperation>
T reduce(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class T, class BinaryOperation>
T reduce(ExecutionPolicy &&exec,
InputIterator first, InputIterator last, T init,
BinaryOperation binary_op);
template<class InputIterator, class OutputIterator>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator>
OutputIterator
exclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result);
template<class InputIterator, class OutputIterator,
class T>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
T init);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class T>
OutputIterator
exclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
T init);
template<class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
exclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
template<class InputIterator, class OutputIterator>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator>
OutputIterator
inclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result);
template<class InputIterator, class OutputIterator,
class BinaryOperation>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class BinaryOperation>
OutputIterator
inclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op);
template<class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
inclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
}
template<class InputIterator>
typename iterator_traits<InputIterator>::value_type
reduce(InputIterator first, InputIterator last);
template<class ExecutionPolicy,
class InputIterator>
typename iterator_traits<InputIterator>::value_type
reduce(ExecutionPolicy &&exec,
InputIterator first, InputIterator last);
-
Effects: The second algorithm's execution is parallelized as determined by
exec
. -
Returns: The result of the sum of
T(0)
and the elements in the range[first,last)
.The order of operands of the sum is unspecified.
-
Requires: Let
T
be the type ofInputIterator
's value type, thenT(0)
shall be a valid expression. Theoperator+
function associated withT
shall have associativity and commutativity.operator+
shall not invalidate iterators or subranges, nor modify elements in the range[first,last)
. -
Complexity:
O(last - first)
. -
Remarks: The second signature shall not participate in overload resolution if
is_execution_policy<ExecutionPolicy>::value
isfalse
.
template<class InputIterator, class T>
T reduce(InputIterator first, InputIterator last, T init);
template<class ExecutionPolicy,
class InputIterator, class T>
T reduce(ExecutionPolicy &&exec,
InputIterator first, InputIterator last, T init);
template<class InputIterator, class T, class BinaryOperation>
T reduce(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class T, class BinaryOperation>
T reduce(ExecutionPolicy &&exec,
InputIterator first, InputIterator last, T init,
BinaryOperation binary_op);
-
Effects: The execution of the second and fourth algorithms is parallelized as determined by
exec
. -
Returns: The result of the generalized sum of
init
and the elements in the range[first,last)
.Sums of elements are evaluated with
operator+
orbinary_op
. The order of operands of the sum is unspecified. -
Requires: The
operator+
function associated withInputIterator
's value type orbinary_op
shall have associativity and commutativity.Neither
operator+
norbinary_op
shall invalidate iterators or subranges, nor modify elements in the range[first,last)
. -
Complexity:
O(last - first)
. -
Remarks: The second and fourth signatures shall not participate in overload resolution if
is_execution_policy<ExecutionPolicy>::value
isfalse
.
template<class InputIterator, class OutputIterator,
class T>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
T init);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class T>
OutputIterator
exclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
T init);
template<class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
exclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
-
Effects: For each iterator
i
in[result,result + (last - first))
, produces a result such that upon completion of the algorithm,*i
yields the generalized sum ofinit
and the elements in the range[first, first + (i - result))
.During execution of the algorithm, every evaluation of the above sum is either of the corresponding form
(init + A) + B)
orA + B
orbinary_op(binary_op(init,A), B)
orbinary_op(A, B)
where there exists some iterator
j
in[first, last)
such that:-
A
is the partial sum of elements in the range[j, j + n)
. -
B
is the partial sum of elements in the range[j + n, j + m)
. -
n
andm
are positive integers andj + m < last
.
The execution of the second and fourth algorithms is parallelized as determined by
exec
. -
-
Returns: The end of the resulting range beginning at
result
. -
Requires: The
operator+
function associated withInputIterator
's value type orbinary_op
shall have associativity.Neither
operator+
norbinary_op
shall invalidate iterators or subranges, nor modify elements in the ranges[first,last)
or[result,result + (last - first))
. -
Complexity:
O(last - first)
. -
Remarks: The second and fourth signatures shall not participate in overload resolution if
is_execution_policy<ExecutionPolicy>::value
isfalse
. -
Notes: The primary difference between
exclusive_scan
andinclusive_scan
is thatexclusive_scan
excludes thei
th input element from thei
th sum.
template<class InputIterator, class OutputIterator>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator>
OutputIterator
inclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result);
template<class InputIterator, class OutputIterator,
class BinaryOperation>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class BinaryOperation>
OutputIterator
inclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op);
template<class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
template<class ExecutionPolicy,
class InputIterator, class OutputIterator,
class T, class BinaryOperation>
OutputIterator
inclusive_scan(ExecutionPolicy &&exec,
InputIterator first, InputIterator last,
OutputIterator result,
T init, BinaryOperation binary_op);
-
Effects: For each iterator
i
in[result,result + (last - first))
, produces a result such that upon completion of the algorithm,*i
yields the generalized sum ofinit
and the elements in the range[first, first + (i - result)]
.During execution of the algorithm, every evaluation of the above sum is either of the corresponding form
(init + A) + B)
orA + B
orbinary_op(binary_op(init,A), B)
orbinary_op(A, B)
where there exists some iterator
j
in[first, last)
such that:-
A
is the partial sum of elements in the range[j, j + n)
. -
B
is the partial sum of elements in the range[j + n, j + m)
. -
n
andm
are positive integers andj + m < last
.
The execution of the second and fourth algorithms is parallelized as determined by
exec
. -
-
Returns: The end of the resulting range beginning at
result
. -
Requires: The
operator+
function associated withInputIterator
's value type orbinary_op
shall have associativity.Neither
operator+
norbinary_op
shall invalidate iterators or subranges, nor modify elements in the ranges[first,last)
or[result,result + (last - first))
. -
Complexity:
O(last - first)
. -
Remarks: The second, fourth, and sixth signatures shall not participate in overload resolution if
is_execution_policy<ExecutionPolicy>::value
isfalse
. -
Notes: The primary difference between
exclusive_scan
andinclusive_scan
is thatinclusive_scan
includes thei
th input element in thei
th sum.