This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Immediate status.

4444. Fix default template arguments for ranges::replace and ranges::replace_if

Section: 26.7.5 [alg.replace], 26.4 [algorithm.syn] Status: Immediate Submitter: Tim Song Opened: 2025-11-04 Last modified: 2025-11-04

Priority: Not Prioritized

View other active issues in [alg.replace].

View all other issues in [alg.replace].

View all issues with Immediate status.

Discussion:

Addresses US 159-259

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

[Kona 2025-11-04; approved by LWG. Status changed: New → Immediate.]

Proposed resolution:

This wording is relative to N5014.

  1. Modify 26.4 [algorithm.syn], header <algorithm> synopsis, as indicated:

    […]
      namespace ranges {
        template<input_iterator I, sentinel_for<I> S, class Proj = identity,
                 class T1 = projected_value_t<I, Proj>, class T2 = T1iter_value_t<I>>
          requires indirectly_writable<I, const T2&> &&
                   indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
          constexpr I
            replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
        template<input_range R, class Proj = identity,
                 class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1range_value_t<R>>
          requires indirectly_writable<iterator_t<R>, const T2&> &&
                   indirect_binary_predicate<ranges::equal_to,
                                             projected<iterator_t<R>, Proj>, const T1*>
          constexpr borrowed_iterator_t<R>
            replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
    
        template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
                 class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = T1iter_value_t<I>>
          requires indirectly_writable<I, const T2&> &&
                   indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
          I replace(Ep&& exec, I first, S last,
                    const T1& old_value, const T2& new_value, Proj proj = {});  // freestanding-deleted
        template<execution-policy Ep, sized-random-access-range R, class Proj = identity,
                 class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1range_value_t<R>>
          requires indirectly_writable<iterator_t<R>, const T2&> &&
                   indirect_binary_predicate<ranges::equal_to,
                                             projected<iterator_t<R>, Proj>, const T1*>
          borrowed_iterator_t<R>
            replace(Ep&& exec, R&& r, const T1& old_value, const T2& new_value,
                    Proj proj = {});                                            // freestanding-deleted
    
        template<input_iterator I, sentinel_for<I> S, class Proj = identity,
                 class T = projectediter_value_t<I, Proj>,
                 indirect_unary_predicate<projected<I, Proj>> Pred>
          requires indirectly_writable<I, const T&>
          constexpr I replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
        template<input_range R, class Proj = identity, class T = projected_value_t<Irange_value_t<R, Proj>,
                 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
          requires indirectly_writable<iterator_t<R>, const T&>
          constexpr borrowed_iterator_t<R>
            replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
    
        template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
                 class Proj = identity, class T = projectediter_value_t<I, Proj>,
                 indirect_unary_predicate<projected<I, Proj>> Pred>
          requires indirectly_writable<I, const T&>
          I replace_if(Ep&& exec, I first, S last, Pred pred,
                       const T& new_value, Proj proj = {});         // freestanding-deleted
        template<execution-policy Ep, sized-random-access-range R, class Proj = identity,
                 class T = projected_value_t<iterator_t<R>range_value_t<R, Proj>,
                 indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
          requires indirectly_writable<iterator_t<R>, const T&>
          borrowed_iterator_t<R>
            replace_if(Ep&& exec, R&& r, Pred pred, const T& new_value,
                       Proj proj = {});                             // freestanding-deleted
      }
    […]
    
  2. Modify 26.7.5 [alg.replace] as indicated:

    […]
    template<input_iterator I, sentinel_for<I> S, class Proj = identity,
             class T1 = projected_value_t<I, Proj>, class T2 = T1iter_value_t<I>>
      requires indirectly_writable<I, const T2&> &&
               indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
      constexpr I
        ranges::replace(I first, S last, const T1& old_value, const T2& new_value, Proj proj = {});
    template<input_range R, class Proj = identity,
             class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1range_value_t<R>>
      requires indirectly_writable<iterator_t<R>, const T2&> &&
               indirect_binary_predicate<ranges::equal_to,
                                         projected<iterator_t<R>, Proj>, const T1*>
      constexpr borrowed_iterator_t<R>
        ranges::replace(R&& r, const T1& old_value, const T2& new_value, Proj proj = {});
    
    template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
             class Proj = identity, class T1 = projected_value_t<I, Proj>, class T2 = T1iter_value_t<I>>
      requires indirectly_writable<I, const T2&> &&
               indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T1*>
      I ranges::replace(Ep&& exec, I first, S last,
                        const T1& old_value, const T2& new_value, Proj proj = {});
    template<execution-policy Ep, sized-random-access-range R, class Proj = identity,
             class T1 = projected_value_t<iterator_t<R>, Proj>, class T2 = T1range_value_t<R>>
      requires indirectly_writable<iterator_t<R>, const T2&> &&
               indirect_binary_predicate<ranges::equal_to,
                                         projected<iterator_t<R>, Proj>, const T1*>
      borrowed_iterator_t<R>
        ranges::replace(Ep&& exec, R&& r, const T1& old_value, const T2& new_value,
                        Proj proj = {});
    
    template<input_iterator I, sentinel_for<I> S, class Proj = identity,
             class T = projectediter_value_t<I, Proj>,
             indirect_unary_predicate<projected<I, Proj>> Pred>
      requires indirectly_writable<I, const T&>
      constexpr I ranges::replace_if(I first, S last, Pred pred, const T& new_value, Proj proj = {});
    template<input_range R, class Proj = identity, class T = projected_value_t<Irange_value_t<R, Proj>,
             indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
      requires indirectly_writable<iterator_t<R>, const T&>
      constexpr borrowed_iterator_t<R>
        ranges::replace_if(R&& r, Pred pred, const T& new_value, Proj proj = {});
    
    template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
             class Proj = identity, class T = projectediter_value_t<I, Proj>,
             indirect_unary_predicate<projected<I, Proj>> Pred>
      requires indirectly_writable<I, const T&>
      I ranges::replace_if(Ep&& exec, I first, S last, Pred pred,
                           const T& new_value, Proj proj = {});
    template<execution-policy Ep, sized-random-access-range R, class Proj = identity,
             class T = projected_value_t<iterator_t<R>range_value_t<R, Proj>,
             indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
      requires indirectly_writable<iterator_t<R>, const T&>
      borrowed_iterator_t<R>
        ranges::replace_if(Ep&& exec, R&& r, Pred pred, const T& new_value,
                           Proj proj = {});
    

    -1- […]