Issue 3058: Parallel adjacent_difference shouldn't require creating temporaries (original) (raw)
template<class InputIterator, class OutputIterator> OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 adjacent_difference(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);
template<class InputIterator, class OutputIterator, class BinaryOperation> OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation> ForwardIterator2 adjacent_difference(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op);
-?- Let
Tbe the value type ofdecltype(first). For the overloads that do not take an argumentbinary_op, letbinary_opbe an lvalue that denotes an object of typeconst minus<>.-1- Requires:
- (1.1) — For the overloads with no
ExecutionPolicy,InputIterator’s value typeTshall beMoveAssignable(Table 25) and shall be constructible from the type of*first.acc(defined below) shall be writable (24.3.1 [iterator.requirements.general]) to theresultoutput iterator. The result of the expressionval - std::move(acc)orbinary_op(val, std::move(acc))shall be writable to theresultoutput iterator.- (1.2) — For the overloads with an
ExecutionPolicy, thevalue type ofresult of the expressionsForwardIterator1shall beCopyConstructible(Table 24), constructible from the expression*first - *firstorbinary_op(*first, *first), and assignable to the value type ofForwardIterator2binary_op(*first, *first)and*firstshall be writable toresult.- (1.3) — […]
-2- Effects: For the overloads with no
ExecutionPolicyand a non-empty range, the function creates an accumulatoraccwhose type isof typeInputIterator’s value typeT, initializes it with*first, and assigns the result to*result. For every iteratoriin[first + 1, last)in order, creates an objectvalwhose type isInputIterator’s value typeT, initializes it with*i, computesval - std::move(acc)orbinary_op(val, std::move(acc)), assigns the result to*(result + (i - first)), and move assigns fromvaltoacc.-3- For the overloads with an
ExecutionPolicyand a non-empty range,first the function creates an object whose type isperformsForwardIterator1's value type, initializes it with*first, and assigns the result to*result. Then for everydin[1, last - first - 1], creates an objectvalwhose type isForwardIterator1's value type, initializes it with*(first + d) - *(first + d - 1)orbinary_op(*(first + d), *(first + d - 1)), and assigns the result to*(result + d)*result = *first. Then, for everydin[1, last - first - 1], performs*(result + d) = binary_op(*(first + d), *(first + (d - 1))).