@@ -695,16 +695,18 @@ template <typename RandomAccessIterator, typename Compare, typename Projection>
695695 */
696696template <
697697 std::random_access_iterator Iterator,
698+ std::sentinel_for<Iterator> Sentinel,
698699 typename Compare = std::ranges::less,
699700 typename Projection = std::identity
700701>
701702 requires std::sortable<Iterator, Compare, Projection>
702- void timmerge (Iterator first, Iterator middle, Iterator last,
703+ void timmerge (Iterator first, Iterator middle, Sentinel last,
703704 Compare comp={}, Projection proj={}) {
705+ auto last_it = std::ranges::next (first, last);
704706 GFX_TIMSORT_AUDIT (std::is_sorted (first, middle, comp, proj) && " Precondition" );
705- GFX_TIMSORT_AUDIT (std::is_sorted (middle, last , comp, proj) && " Precondition" );
706- detail::TimSort<Iterator, Compare, Projection>::merge (first, middle, last , comp, proj);
707- GFX_TIMSORT_AUDIT (std::is_sorted (first, last , comp, proj) && " Postcondition" );
707+ GFX_TIMSORT_AUDIT (std::is_sorted (middle, last_it , comp, proj) && " Precondition" );
708+ detail::TimSort<Iterator, Compare, Projection>::merge (first, middle, last_it , comp, proj);
709+ GFX_TIMSORT_AUDIT (std::is_sorted (first, last_it , comp, proj) && " Postcondition" );
708710}
709711
710712/* *
@@ -728,14 +730,16 @@ void timmerge(Range &&range, std::ranges::iterator_t<Range> middle,
728730 */
729731template <
730732 std::random_access_iterator Iterator,
733+ std::sentinel_for<Iterator> Sentinel,
731734 typename Compare = std::ranges::less,
732735 typename Projection = std::identity
733736>
734737 requires std::sortable<Iterator, Compare, Projection>
735- void timsort (Iterator first, Iterator last,
738+ void timsort (Iterator first, Sentinel last,
736739 Compare comp={}, Projection proj={}) {
737- detail::TimSort<Iterator, Compare, Projection>::sort (first, last, comp, proj);
738- GFX_TIMSORT_AUDIT (std::is_sorted (first, last, comp, proj) && " Postcondition" );
740+ auto last_it = std::ranges::next (first, last);
741+ detail::TimSort<Iterator, Compare, Projection>::sort (first, last_it, comp, proj);
742+ GFX_TIMSORT_AUDIT (std::is_sorted (first, last_it, comp, proj) && " Postcondition" );
739743}
740744
741745/* *
0 commit comments