From f181de9df4c43f188ae932a412af32a0981c9067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Wed, 3 Apr 2024 12:29:51 +0200 Subject: [PATCH] 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. --- .../catch_uniform_integer_distribution.hpp | 18 +----------------- .../RandomNumberGeneration.tests.cpp | 4 +++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/catch2/internal/catch_uniform_integer_distribution.hpp b/src/catch2/internal/catch_uniform_integer_distribution.hpp index afa2015d9f..3332489adc 100644 --- a/src/catch2/internal/catch_uniform_integer_distribution.hpp +++ b/src/catch2/internal/catch_uniform_integer_distribution.hpp @@ -13,22 +13,6 @@ namespace Catch { - namespace Detail { - // Indirection to enable make_unsigned behaviour. - template - struct make_unsigned { - using type = std::make_unsigned_t; - }; - - template <> - struct make_unsigned { - using type = uint8_t; - }; - - template - using make_unsigned_t = typename make_unsigned::type; - } - /** * Implementation of uniform distribution on integers. * @@ -44,7 +28,7 @@ template class uniform_integer_distribution { static_assert(std::is_integral::value, "..."); - using UnsignedIntegerType = Detail::make_unsigned_t; + using UnsignedIntegerType = Detail::SizedUnsignedType_t; // Only the left bound is stored, and we store it converted to its // unsigned image. This avoids having to do the conversions inside diff --git a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp index 8517d61737..327b65ee9c 100644 --- a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp @@ -140,7 +140,9 @@ TEMPLATE_TEST_CASE( "uniform_integer_distribution can handle unit ranges", uint32_t, int32_t, uint64_t, - int64_t ) { + int64_t, + size_t, + ptrdiff_t) { // We want random seed to sample different parts of the rng state, // the output is predetermined anyway std::random_device rd;