-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use _Invoke_result_t<_Urng&>
instead of _Urng::result_type
in _Rng_from_urng
#3002
Conversation
Thanks for finding and fixing this bug! I've pushed a fix for value categories with a corresponding test change (fails without the fix, passes with it). |
That's true for the concept, but doesn't [rand.req.urng]/3 require " |
Old Since If we want to be strict, we could change |
I see, thanks for explaining.
… On Aug 7, 2022, at 10:17 PM, S. B. Tam ***@***.***> wrote:
C++20 uniform_random_bit_generator does not require the presence of member result_type
That's true for the concept, but doesn't [rand.req.urng]/3 require "G provides a nested typedef-name result_type that denotes the same type as invoke_result_t<G&>"? These generators in libc++ meet the URBG concept, but not the named requirements.
Old std::shuffle requires the generator type to meet the uniform random bit generator named requirements (and thus requires member result_type), but C++20 ranges::shuffle only requires the type to model the concept.
Since ranges::shuffle uses _Rng_from_urng, the latter must not rely on result_type.
If we want to be strict, we could change std::shuffle to check the presence of result_type.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.
|
@@ -5705,12 +5705,12 @@ 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; | |||
using _Ty1 = _Invoke_result_t<_Urng&>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't _Invoke_result_t<_Urng&>
a bit heavyweight when we could simply decltype(_STD declval<_Urng&>()())
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but I don't think that this will ever be frequently instantiated in a program - so I'm not concerned about throughput here.
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
_Invoke_result_t<_Urng>
instead of _Urng::result_type
in _Rng_from_urng
_Invoke_result_t<_Urng&>
instead of _Urng::result_type
in _Rng_from_urng
Thanks for randomly fixing this bug! 🐞 🛠️ 😹 |
…ng_from_urng` (microsoft#3002) Co-authored-by: Stephan T. Lavavej <[email protected]>
C++20
uniform_random_bit_generator
does not require the presence of memberresult_type
.This is tested in libc++ tests
std/algorithms/alg.modifying.operations/alg.random.shuffle/ranges_shuffle.pass.cpp
andstd/algorithms/alg.modifying.operations/alg.random.sample/ranges_sample.pass.cpp
. Unfortunately they fail even after this change, because they assume thatstd::array
iterators are pointers.