mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-16 10:42:25 +01:00
Use SizedUnsignedType_t to pick UnsignedType for uniform_integer_distribution
The previously used `make_unsigned` approach combined with the overload set of `extendedMult` caused compilation issues on MacOS platform. By forcing the selection to be one of `std::uintX_t` types we don't need to complicate the overload set further.
This commit is contained in:
parent
9271083a04
commit
f181de9df4
@ -13,22 +13,6 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
namespace Detail {
|
|
||||||
// Indirection to enable make_unsigned<bool> behaviour.
|
|
||||||
template <typename T>
|
|
||||||
struct make_unsigned {
|
|
||||||
using type = std::make_unsigned_t<T>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct make_unsigned<bool> {
|
|
||||||
using type = uint8_t;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using make_unsigned_t = typename make_unsigned<T>::type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of uniform distribution on integers.
|
* Implementation of uniform distribution on integers.
|
||||||
*
|
*
|
||||||
@ -44,7 +28,7 @@ template <typename IntegerType>
|
|||||||
class uniform_integer_distribution {
|
class uniform_integer_distribution {
|
||||||
static_assert(std::is_integral<IntegerType>::value, "...");
|
static_assert(std::is_integral<IntegerType>::value, "...");
|
||||||
|
|
||||||
using UnsignedIntegerType = Detail::make_unsigned_t<IntegerType>;
|
using UnsignedIntegerType = Detail::SizedUnsignedType_t<sizeof(IntegerType)>;
|
||||||
|
|
||||||
// Only the left bound is stored, and we store it converted to its
|
// Only the left bound is stored, and we store it converted to its
|
||||||
// unsigned image. This avoids having to do the conversions inside
|
// unsigned image. This avoids having to do the conversions inside
|
||||||
|
@ -140,7 +140,9 @@ TEMPLATE_TEST_CASE( "uniform_integer_distribution can handle unit ranges",
|
|||||||
uint32_t,
|
uint32_t,
|
||||||
int32_t,
|
int32_t,
|
||||||
uint64_t,
|
uint64_t,
|
||||||
int64_t ) {
|
int64_t,
|
||||||
|
size_t,
|
||||||
|
ptrdiff_t) {
|
||||||
// We want random seed to sample different parts of the rng state,
|
// We want random seed to sample different parts of the rng state,
|
||||||
// the output is predetermined anyway
|
// the output is predetermined anyway
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
|
Loading…
Reference in New Issue
Block a user