Skip to content

Commit

Permalink
Parallel for_each iterators don't have to be mutable
Browse files Browse the repository at this point in the history
The overloads of for_each that take an execution policy argument do not
require that the iterator arguments always be mutable iterators.  Whether
or not the iterators need to be mutable depends on what the function
object does.  for_each is unusual, if not unique, in this regard; for all
other algorithms the mutability of the iterators is specified by the
algorithm.  See http://eel.is/c++draft/alg.foreach#7 , though I admit that
the wording is not particularly clear about this.

Since the compiler can't realiably figure out whether or not the function
object modifies the elements in the sequence, for_each should only check
for constant iterators (_REQUIRE_PARALLEL_ITERATOR), not mutable iterators
(_REQUIRE_CPP17_MUTABLE_ITERATOR).

This bug was introduced by microsoft#2960 .
That PR should not have changed for_each.
  • Loading branch information
dkolsen-pgi committed Aug 25, 2022
1 parent febb643 commit dbdd17f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion stl/inc/execution
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ struct _Static_partitioned_for_each2 { // for_each task scheduled on the system
template <class _ExPo, class _FwdIt, class _Fn, _Enable_if_execution_policy_t<_ExPo> /* = 0 */>
void for_each(_ExPo&&, _FwdIt _First, _FwdIt _Last, _Fn _Func) noexcept /* terminates */ {
// perform function for each element [_First, _Last) with the indicated execution policy
_REQUIRE_CPP17_MUTABLE_ITERATOR(_FwdIt);
_REQUIRE_PARALLEL_ITERATOR(_FwdIt);
_Adl_verify_range(_First, _Last);
auto _UFirst = _Get_unwrapped(_First);
const auto _ULast = _Get_unwrapped(_Last);
Expand Down

0 comments on commit dbdd17f

Please sign in to comment.