https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121917

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>:

https://gcc.gnu.org/g:349affa42c9fa47a12eb7f5f97f5650a77bbf014

commit r16-3842-g349affa42c9fa47a12eb7f5f97f5650a77bbf014
Author: Patrick Palka <ppa...@redhat.com>
Date:   Sat Sep 13 10:44:12 2025 -0400

    libstdc++: Fix ranges::shuffle for non-sized range [PR121917]

    ranges::shuffle has a two-at-a-time PRNG optimization (copied from
    std::shuffle) that considers the PRNG width vs the size of the range.
    But in C++20 a random access sentinel isn't always sized so we can't
    unconditionally do __last - __first to obtain the size in constant
    time.

    We could instead use ranges::distance, but that'd take linear time for a
    non-sized sentinel which makes the optimization less clear of a win.  So
    this patch instead makes us only consider this optimization for sized
    ranges.

            PR libstdc++/121917

    libstdc++-v3/ChangeLog:

            * include/bits/ranges_algo.h (__shuffle_fn::operator()): Only
            consider the two-at-a-time PRNG optimization if the range is
            sized.
            * testsuite/25_algorithms/shuffle/constrained.cc (test03): New
            test.

    Reviewed-by: Jonathan Wakely <jwak...@redhat.com>

Reply via email to