`<algorithm>`: Should `_Rng_from_urng` use `make-unsigned-like-t`?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
#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.
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the sample with the linked Godbolt code, then inspect stl/inc/xutility around lines 5696-5700 and compare the behavior with [alg.random.sample]. Determine whether the standard permits this integer-class difference_type and whether the make_unsigned_t usage is appropriate; done means a resolved conformance decision with corresponding implementation or regression-test changes if needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100