using __distrib_type = uniform_int_distribution<_Size>;
using __param_type = typename __distrib_type::param_type;
using _USize = __detail::__make_unsigned_like_t<_Size>;
- using __uc_type
- = common_type_t<typename remove_reference_t<_Gen>::result_type, _USize>;
+ using __uc_type = common_type_t<decltype(__g()), _USize>;
if (__first == __last)
return __out;
using __ud_type = __detail::__make_unsigned_like_t<_DistanceType>;
using __distr_type = std::uniform_int_distribution<__ud_type>;
using __p_type = typename __distr_type::param_type;
-
- using __uc_type
- = common_type_t<typename remove_reference_t<_Gen>::result_type, __ud_type>;
+ using __uc_type = common_type_t<decltype(__g()), __ud_type>;
if constexpr (sized_sentinel_for<_Sent, _Iter>)
{
operator()(_UniformRandomBitGenerator& __urng,
const param_type& __param)
{
- typedef typename _UniformRandomBitGenerator::result_type _Gresult_type;
+ typedef decltype(__urng()) _Gresult_type;
typedef typename make_unsigned<result_type>::type __utype;
typedef typename common_type<_Gresult_type, __utype>::type __uctype;
const param_type& __param)
{
__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- typedef typename _UniformRandomBitGenerator::result_type _Gresult_type;
+ typedef decltype(__urng()) _Gresult_type;
typedef typename make_unsigned<result_type>::type __utype;
typedef typename common_type<_Gresult_type, __utype>::type __uctype;
--- /dev/null
+// { dg-do compile { target c++20 } }
+
+// Bug 121919 ranges::sample assumes a uniform_random_bit_generator
+// provides result_type
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+struct G
+{
+ constexpr static unsigned min() { return 0; }
+ constexpr static unsigned max() { return 10; }
+ unsigned operator()() const;
+};
+
+static_assert(std::uniform_random_bit_generator<G>);
+
+void
+test_pr121919()
+{
+ int i2[2]{ 1, 2 };
+ __gnu_test::test_random_access_range from(i2);
+ int i1[1];
+ __gnu_test::test_random_access_range to(i1);
+ std::ranges::sample(from, std::ranges::begin(to), 1, G{});
+ std::ranges::sample(std::ranges::begin(from), std::ranges::end(to),
+ std::ranges::begin(to), 1, G{});
+}
--- /dev/null
+// { dg-do compile { target c++20 } }
+
+// Bug 121919 ranges::shuffle assumes a uniform_random_bit_generator
+// provides result_type
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+struct G
+{
+ constexpr static unsigned min() { return 0; }
+ constexpr static unsigned max() { return 10; }
+ unsigned operator()() const;
+};
+
+static_assert(std::uniform_random_bit_generator<G>);
+
+void
+test_pr121919()
+{
+ int arr[2]{ 1, 2 };
+ __gnu_test::test_random_access_range r(arr);
+ std::ranges::shuffle(r, G{});
+ std::ranges::shuffle(std::ranges::begin(r), std::ranges::end(r), G{});
+}