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

4457. freestanding for stable_sort, stable_partition and inplace_merge

Section: 26.4 [algorithm.syn] Status: New Submitter: Braden Ganetsky Opened: 2025-11-06 Last modified: 2025-12-18

Priority: Not Prioritized

View all other issues in [algorithm.syn].

View all issues with New status.

Discussion:

Addresses US 157-255

This applies the resolution for US 157-255.

Proposed resolution:

This wording is relative to N5014.

  1. Modify 26.4 [algorithm.syn], as indicated:

    namespace ranges {
      template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
               class Proj = identity>
        requires sortable<I, Comp, Proj>
        constexpr I stable_sort(I first, S last, Comp comp = {}, Proj proj = {});         // hosted
      template<random_access_range R, class Comp = ranges::less, class Proj = identity>
        requires sortable<iterator_t<R>, Comp, Proj>
        constexpr borrowed_iterator_t<R>
          stable_sort(R&& r, Comp comp = {}, Proj proj = {});                             // hosted
    
      template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
               class Comp = ranges::less, class Proj = identity>
        requires sortable<I, Comp, Proj>
        I stable_sort(Ep&& exec, I first, S last, Comp comp = {},
                      Proj proj = {});                                        // freestanding-deletedhosted
      template<execution-policy Ep, sized-random-access-range R, class Comp = ranges::less,
               class Proj = identity>
        requires sortable<iterator_t<R>, Comp, Proj>
        borrowed_iterator_t<R>
          stable_sort(Ep&& exec, R&& r, Comp comp = {}, Proj proj = {});      // freestanding-deletedhosted
    }
    
  2. Modify 26.4 [algorithm.syn], as indicated:

    namespace ranges {
      template<bidirectional_iterator I, sentinel_for<I> S, class Proj = identity,
               indirect_unary_predicate<projected<I, Proj>> Pred>
        requires permutable<I>
        constexpr subrange<I> stable_partition(I first, S last, Pred pred,            // hosted
                                               Proj proj = {});
      template<bidirectional_range R, class Proj = identity,
               indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
        requires permutable<iterator_t<R>>
        constexpr borrowed_subrange_t<R> stable_partition(R&& r, Pred pred,           // hosted
                                                          Proj proj = {});
    
      template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
               class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred>
        requires permutable<I>
        subrange<I>
          stable_partition(Ep&& exec, I first, S last, Pred pred,
                           Proj proj = {});                                   // freestanding-deletedhosted
      template<execution-policy Ep, sized-random-access-range R, class Proj = identity,
               indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
        requires permutable<iterator_t<R>>
        borrowed_subrange_t<R>
          stable_partition(Ep&& exec, R&& r, Pred pred, Proj proj = {});      // freestanding-deletedhosted
    }
    
  3. Modify 26.4 [algorithm.syn], as indicated:

    namespace ranges {
      template<bidirectional_iterator I, sentinel_for<I> S, class Comp = ranges::less,
               class Proj = identity>
        requires sortable<I, Comp, Proj>
        constexpr I
          inplace_merge(I first, I middle, S last, Comp comp = {}, Proj proj = {});       // hosted
      template<bidirectional_range R, class Comp = ranges::less, class Proj = identity>
        requires sortable<iterator_t<R>, Comp, Proj>
        constexpr borrowed_iterator_t<R>
          inplace_merge(R&& r, iterator_t<R> middle, Comp comp = {}, Proj proj = {});     // hosted
    
      template<execution-policy Ep, random_access_iterator I, sized_sentinel_for<I> S,
               class Comp = ranges::less, class Proj = identity>
        requires sortable<I, Comp, Proj>
        I inplace_merge(Ep&& exec, I first, I middle, S last, Comp comp = {},
                        Proj proj = {});                          // freestanding-deletedhosted
      template<execution-policy Ep, sized-random-access-range R, class Comp = ranges::less,
               class Proj = identity>
        requires sortable<iterator_t<R>, Comp, Proj>
        borrowed_iterator_t<R>
          inplace_merge(Ep&& exec, R&& r, iterator_t<R> middle, Comp comp = {},
                        Proj proj = {});                          // freestanding-deletedhosted
    }