mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 14:59:39 +02:00
The ranges::sample and ranges::shuffle algorithms are supposed to work with types which model std::uniform_random_bit_generator, which means they should not assume that G::result_type is present. That isn't needed to satisfy the concept. Change the algorithms to use decltype(__g()) instead of using result_type. This isn't sufficient to fix the bug though, because those algorithms use std::uniform_int_distribution and that class template's operator() overloads depend on the more restrictive uniform random bit generator requirements, which do include the presence of a nested result_type member. We need to change std::uniform_int_distribution to also use decltype instead of the nested result_type, even though the standard says that std::uniform_int_distribution is allowed to assume that result_type exists. There's yet another problem, which is that a type that returns random bool values can model the concept, but doesn't meet the named requirements and can't be used with std::uniform_int_distribution. That isn't addressed by this change. libstdc++-v3/ChangeLog: PR libstdc++/121919 * include/bits/ranges_algo.h (__sample_fn, __shuffle_fn): Use decltype(__g()) instead of remove_reference_t<_G>::result_type. * include/bits/uniform_int_dist.h (uniform_int_distribution::operator()): Use decltype(__urng()) instead of _UniformRandomBitGenerator::result_type (uniform_int_distribution::__generate_impl): Likewise. * testsuite/25_algorithms/sample/121919.cc: New test. * testsuite/25_algorithms/shuffle/121919.cc: New test. Reviewed-by: Nathan Myers <nmyers@redhat.com>