https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96731
Bug ID: 96731 Summary: uniform_int_distribution requirement that its type is_integral is too strict Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: TonyELewis at hotmail dot com Target Milestone: --- Following on from https://github.com/ericniebler/range-v3/issues/1532 ... I think the static_assert requirement in libstdc++'s uniform_int_distribution code that its template argument type is_integral may be too strict. I can't see any obvious mention of constraints on uniform_int_distribution's IntType in http://eel.is/c++draft/rand.dist.uni.int The motivating case is attempting to sample from a range-v3 view::indices. The range-v3 clever tricks lead to uniform_int_distribution being invoked with a range-v3 type. This all works OK under libc++ because it doesn't impose any requirements on the type. But the aforementioned static_assert in libstdc++ won't allow it. The problem can be seen with the first error under GCC or Clang with -std=c++17 on this code: #include <algorithm> #include <iterator> #include <random> #include <vector> #include <range/v3/view/indices.hpp> void fill_vec_with_random_sample_of_first_n_ints( const size_t &prm_num_possible_vals, std::vector<size_t> &prm_result, std::mt19937 &prm_rng ) { auto some_indices = ranges::views::indices( prm_num_possible_vals ); std::sample( std::begin( some_indices ), std::end ( some_indices ), std::begin( prm_result ), static_cast<ptrdiff_t>( prm_result.size() ), prm_rng ); } Compiler Explorer : https://godbolt.org/z/MxrazP One option is that libstdc++ could use std::numeric_limits<T>::is_integer instead of std::is_integral, so that range-v3 could then specialise accordingly for its type.