#include <vector>
#include <random>
#include <ranges>
#include <algorithm>
int main() {
std::vector<std::size_t> v(10);
std::ranges::sample(
std::views::iota(0ULL, 42ULL),
v.begin(), 3, std::mt19937{std::random_device{}()});
}
https://godbolt.org/z/bMredxf58
In the above example, the difference_type of iota_view is _Signed128, which makes the instantiation of _Rng_from_urng fail since it uses make_unsigned_t which cannot work with integer-class types.
|
template <class _Diff, class _Urng>
|
|
class _Rng_from_urng { // wrap a URNG as an RNG
|
|
public:
|
|
using _Ty0 = make_unsigned_t<_Diff>;
|
|
using _Ty1 = typename _Urng::result_type;
|
It's worth noting that gcc will only work with -std=gnu++20 because __int128 is an integer type only in gnu-mode. gcc will also fail the static_assert under -std=c++20, but this assertion comes from the implementation of std::sample, so there is no reference value because std::sample is not for C++20 iterators system.
In [alg.random.sample], I don't see any requirement that the above code violates, so should I consider it a bug?
https://godbolt.org/z/bMredxf58
In the above example, the
difference_typeofiota_viewis_Signed128, which makes the instantiation of_Rng_from_urngfail since it usesmake_unsigned_twhich cannot work with integer-class types.STL/stl/inc/xutility
Lines 5696 to 5700 in ef62d3f
It's worth noting that gcc will only work with
-std=gnu++20because__int128is an integer type only in gnu-mode. gcc will also fail thestatic_assertunder-std=c++20, but this assertion comes from the implementation ofstd::sample, so there is no reference value becausestd::sampleis not for C++20 iterators system.In [alg.random.sample], I don't see any requirement that the above code violates, so should I consider it a bug?