Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,8 @@ In-place Mutating Operations
// replace
template <typename ExecutionPolicy, std::ranges::random_access_range R,
typename Proj = std::identity,
typename T1 = /*projected-value-type*/<std::ranges::iterator_t<R>, Proj>, typename T2 = T1>
typename T1 = /*projected-value-type*/<std::ranges::iterator_t<R>, Proj>,
typename T2 = std::ranges::range_value_t<R>>
Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This asymmetry between old_value and new_value seems odd at first, given their names.

However, I understand that this asymmetry is necessary. It's like replacing by key. We specify a key (projection applied), old_value, and we specify a key-value pair, new_value, to replace a found entry with.

I agree that we should act proactively. But, I would anticipate more changes in the standard, e.g. different names of the arguments, which is not crucial.

Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default template argument for the type of the new value in range::replace and ranges::replace_if should not have projections applied.

Where can I find these discussions of the c++ draft?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://cplusplus.github.io/LWG/lwg-active.html#4444 is the official issue, opened just recently. Our changes are aligned with the proposed resolution.

requires oneapi::dpl::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>> &&
std::ranges::sized_range<R> &&
std::indirectly_writable<std::ranges::iterator_t<R>, const T2&> &&
Expand All @@ -882,7 +883,7 @@ In-place Mutating Operations
// replace_if
template <typename ExecutionPolicy, std::ranges::random_access_range R,
typename Proj = std::identity,
typename T = /*projected-value-type*/<std::ranges::iterator_t<R>, Proj>,
typename T = std::ranges::range_value_t<R>,
std::indirect_unary_predicate< std::projected<std::ranges::iterator_t<R>, Proj> > Pred>
requires oneapi::dpl::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>> &&
std::ranges::sized_range<R> &&
Expand Down
Loading