|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4444" status="New"> |
| 5 | +<title>Fix default template arguments for `ranges::replace` and `ranges::replace_if`</title> |
| 6 | +<section> |
| 7 | +<sref ref="[alg.replace]"/><sref ref="[algorithm.syn]"/> |
| 8 | +</section> |
| 9 | +<submitter>Tim Song</submitter> |
| 10 | +<date>04 Nov 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<b>Addresses <a href="https://github.com/cplusplus/nbballot/issues/834">US 159-259</a></b> |
| 15 | +<p>The default template argument for the type of the new value in |
| 16 | +`ranges::replace` and `ranges::replace_if` should not have projections applied.</p> |
| 17 | +</discussion> |
| 18 | + |
| 19 | +<resolution> |
| 20 | +<p> |
| 21 | +This wording is relative to <paper num="N5014"/>. |
| 22 | +</p> |
| 23 | + |
| 24 | +<ol> |
| 25 | + |
| 26 | +<li><p>Modify <sref ref="[algorithm.syn]"/>, header <tt><algorithm></tt> synopsis, as indicated:</p> |
| 27 | + |
| 28 | +<blockquote> |
| 29 | +<pre> |
| 30 | +[…] |
| 31 | + namespace ranges { |
| 32 | + template<input_iterator I, sentinel_for<I> S, class Proj = identity, |
| 33 | + class T1 = projected_value_t<I, Proj>, class T2 = <del>T1</del><ins>iter_value_t<I></ins>> |
| 34 | + requires indirectly_writable<I, const T2&> && |
| 35 | + indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*> |
| 36 | + constexpr I |
| 37 | + replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {}); |
| 38 | + template<input_range R, class Proj = identity, |
| 39 | + class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = <del>T1</del><ins>range_value_t<R></ins>> |
| 40 | + requires indirectly_writable<iterator_t<R>, const T2&> && |
| 41 | + indirect_binary_predicate<ranges::equal_to, |
| 42 | + projected<iterator_t<R>, Proj>, const T1*> |
| 43 | + constexpr borrowed_iterator_t<R> |
| 44 | + replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {}); |
| 45 | + |
| 46 | + template<<i>execution-policy</i> Ep, random_access_iterator I, sized_sentinel_for<I> S, |
| 47 | + class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = <del>T1</del><ins>iter_value_t<I></ins>> |
| 48 | + requires indirectly_writable<I, const T2&> && |
| 49 | + indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*> |
| 50 | + I replace(Ep&& exec, I first, S last, |
| 51 | + const T1& old_value, const T2& new_value, Proj proj = {}); // <i>freestanding-deleted</i> |
| 52 | + template<<i>execution-policy</i> Ep, <i>sized-random-access-range</i> R, class Proj = identity, |
| 53 | + class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = <del>T1</del><ins>range_value_t<R></ins>> |
| 54 | + requires indirectly_writable<iterator_t<R>, const T2&> && |
| 55 | + indirect_binary_predicate<ranges::equal_to, |
| 56 | + projected<iterator_t<R>, Proj>, const T1*> |
| 57 | + borrowed_iterator_t<R> |
| 58 | + replace(Ep&& exec, R&& r, const T1& old_value, const T2& new_value, |
| 59 | + Proj proj = {}); // <i>freestanding-deleted</i> |
| 60 | + |
| 61 | + template<input_iterator I, sentinel_for<I> S, class Proj = identity, |
| 62 | + class T = <del>projected_</del><ins>iter_</ins>value_t<I, Proj>, |
| 63 | + indirect_unary_predicate<projected<I, Proj>> Pred> |
| 64 | + requires indirectly_writable<I, const T&> |
| 65 | + constexpr I replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {}); |
| 66 | + template<input_range R, class Proj = identity, class T = <del>projected_value_t<I</del><ins>range_value_t<R</ins>, Proj>, |
| 67 | + indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred> |
| 68 | + requires indirectly_writable<iterator_t<R>, const T&> |
| 69 | + constexpr borrowed_iterator_t<R> |
| 70 | + replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); |
| 71 | + |
| 72 | + template<<i>execution-policy</i> Ep, random_access_iterator I, sized_sentinel_for<I> S, |
| 73 | + class Proj = identity, class T = <del>projected</del><ins>iter</ins>_value_t<I, Proj>, |
| 74 | + indirect_unary_predicate<projected<I, Proj>> Pred> |
| 75 | + requires indirectly_writable<I, const T&> |
| 76 | + I replace_if(Ep&& exec, I first, S last, Pred pred, |
| 77 | + const T& new_value, Proj proj = {}); // <i>freestanding-deleted</i> |
| 78 | + template<<i>execution-policy</i> Ep, <i>sized-random-access-range</i> R, class Proj = identity, |
| 79 | + class T = <del>projected_value_t<iterator_t<R></del><ins>range_value_t<R</ins>, Proj>, |
| 80 | + indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred> |
| 81 | + requires indirectly_writable<iterator_t<R>, const T&> |
| 82 | + borrowed_iterator_t<R> |
| 83 | + replace_if(Ep&& exec, R&& r, Pred pred, const T& new_value, |
| 84 | + Proj proj = {}); // <i>freestanding-deleted</i> |
| 85 | + } |
| 86 | +[…] |
| 87 | +</pre> |
| 88 | +</blockquote> |
| 89 | +</li> |
| 90 | +<li><p>Modify <sref ref="[alg.replace]"/> as indicated:</p> |
| 91 | + |
| 92 | +<blockquote> |
| 93 | +<pre> |
| 94 | +[…] |
| 95 | +template<input_iterator I, sentinel_for<I> S, class Proj = identity, |
| 96 | + class T1 = projected_value_t<I, Proj>, class T2 = <del>T1</del><ins>iter_value_t<I></ins>> |
| 97 | + requires indirectly_writable<I, const T2&> && |
| 98 | + indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*> |
| 99 | + constexpr I |
| 100 | + ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {}); |
| 101 | +template<input_range R, class Proj = identity, |
| 102 | + class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = <del>T1</del><ins>range_value_t<R></ins>> |
| 103 | + requires indirectly_writable<iterator_t<R>, const T2&> && |
| 104 | + indirect_binary_predicate<ranges::equal_to, |
| 105 | + projected<iterator_t<R>, Proj>, const T1*> |
| 106 | + constexpr borrowed_iterator_t<R> |
| 107 | + ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {}); |
| 108 | + |
| 109 | +template<<i>execution-policy</i> Ep, random_access_iterator I, sized_sentinel_for<I> S, |
| 110 | + class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = <del>T1</del><ins>iter_value_t<I></ins>> |
| 111 | + requires indirectly_writable<I, const T2&> && |
| 112 | + indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*> |
| 113 | + I ranges::replace(Ep&& exec, I first, S last, |
| 114 | + const T1& old_value, const T2& new_value, Proj proj = {}); |
| 115 | +template<<i>execution-policy</i> Ep, <i>sized-random-access-range</i> R, class Proj = identity, |
| 116 | + class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = <del>T1</del><ins>range_value_t<R></ins>> |
| 117 | + requires indirectly_writable<iterator_t<R>, const T2&> && |
| 118 | + indirect_binary_predicate<ranges::equal_to, |
| 119 | + projected<iterator_t<R>, Proj>, const T1*> |
| 120 | + borrowed_iterator_t<R> |
| 121 | + ranges::replace(Ep&& exec, R&& r, const T1& old_value, const T2& new_value, |
| 122 | + Proj proj = {}); |
| 123 | + |
| 124 | +template<input_iterator I, sentinel_for<I> S, class Proj = identity, |
| 125 | + class T = <del>projected_</del><ins>iter_</ins>value_t<I, Proj>, |
| 126 | + indirect_unary_predicate<projected<I, Proj>> Pred> |
| 127 | + requires indirectly_writable<I, const T&> |
| 128 | + constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {}); |
| 129 | +template<input_range R, class Proj = identity, class T = <del>projected_value_t<I</del><ins>range_value_t<R</ins>, Proj>, |
| 130 | + indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred> |
| 131 | + requires indirectly_writable<iterator_t<R>, const T&> |
| 132 | + constexpr borrowed_iterator_t<R> |
| 133 | + ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {}); |
| 134 | + |
| 135 | +template<<i>execution-policy</i> Ep, random_access_iterator I, sized_sentinel_for<I> S, |
| 136 | + class Proj = identity, class T = <del>projected</del><ins>iter</ins>_value_t<I, Proj>, |
| 137 | + indirect_unary_predicate<projected<I, Proj>> Pred> |
| 138 | + requires indirectly_writable<I, const T&> |
| 139 | + I ranges::replace_if(Ep&& exec, I first, S last, Pred pred, |
| 140 | + const T& new_value, Proj proj = {}); |
| 141 | +template<<i>execution-policy</i> Ep, <i>sized-random-access-range</i> R, class Proj = identity, |
| 142 | + class T = <del>projected_value_t<iterator_t<R></del><ins>range_value_t<R</ins>, Proj>, |
| 143 | + indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred> |
| 144 | + requires indirectly_writable<iterator_t<R>, const T&> |
| 145 | + borrowed_iterator_t<R> |
| 146 | + ranges::replace_if(Ep&& exec, R&& r, Pred pred, const T& new_value, |
| 147 | + Proj proj = {}); |
| 148 | +</pre> |
| 149 | +<blockquote> |
| 150 | +<p> |
| 151 | +-1- […] |
| 152 | +</p> |
| 153 | +</blockquote> |
| 154 | +</blockquote> |
| 155 | +</li> |
| 156 | +</ol> |
| 157 | + |
| 158 | +</resolution> |
| 159 | + |
| 160 | +</issue> |
0 commit comments