diff --git a/stl/inc/xutility b/stl/inc/xutility index 30bcfb7b62..45d986a6b6 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -5705,12 +5705,12 @@ template 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&>; using _Udiff = conditional_t; explicit _Rng_from_urng(_Urng& _Func) : _Ref(_Func), _Bits(CHAR_BIT * sizeof(_Udiff)), _Bmask(_Udiff(-1)) { - for (; (_Urng::max)() - (_Urng::min)() < _Bmask; _Bmask >>= 1) { + for (; static_cast<_Udiff>((_Urng::max)() - (_Urng::min)()) < _Bmask; _Bmask >>= 1) { --_Bits; } } @@ -5754,7 +5754,7 @@ public: private: _Udiff _Get_bits() { // return a random value within [0, _Bmask] for (;;) { // repeat until random value is in range - _Udiff _Val = _Ref() - (_Urng::min)(); + _Udiff _Val = static_cast<_Udiff>(_Ref() - (_Urng::min)()); if (_Val <= _Bmask) { return _Val; diff --git a/tests/std/tests/P0896R4_ranges_alg_shuffle/test.cpp b/tests/std/tests/P0896R4_ranges_alg_shuffle/test.cpp index 1a82decb40..876af1242a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_shuffle/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_shuffle/test.cpp @@ -51,6 +51,25 @@ struct instantiator { } }; +void test_urbg() { // COMPILE-ONLY + struct RandGen { + static constexpr bool min() { + return false; + } + static constexpr bool max() { + return true; + } + bool operator()() & { + return false; + } + }; + + STATIC_ASSERT(uniform_random_bit_generator); + + int arr[1] = {}; + ranges::shuffle(arr, RandGen{}); +} + int main() { printf("Using seed: %u\n", seed);