Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-06-02 12:15:29 +0200
committerMartin Hořeňovský2022-06-02 12:15:35 +0200
commit4142e699c2d970ee039bb1cfd406401f7d94393e (patch)
treeab45770bf13b4847b37375e6fe9d266400c231f3 /src
parent9e445930cc22d2a80617b3198a7a260bc31c4ae4 (diff)
downloadcatch3-4142e699c2d970ee039bb1cfd406401f7d94393e.tar.gz
Add full set of constraints to random integral generator
Related to #2433
Diffstat (limited to 'src')
-rw-r--r--src/catch2/generators/catch_generators_random.hpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/catch2/generators/catch_generators_random.hpp b/src/catch2/generators/catch_generators_random.hpp
index 15043211..8b2c4949 100644
--- a/src/catch2/generators/catch_generators_random.hpp
+++ b/src/catch2/generators/catch_generators_random.hpp
@@ -65,12 +65,17 @@ public:
}
};
-// TODO: Ideally this would be also constrained against the various char types,
-// but I don't expect users to run into that in practice.
template <typename T>
-std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value,
-GeneratorWrapper<T>>
+std::enable_if_t<std::is_integral<T>::value, GeneratorWrapper<T>>
random(T a, T b) {
+ static_assert(
+ !std::is_same<T, char>::value &&
+ !std::is_same<T, uint8_t>::value &&
+ !std::is_same<T, uint8_t>::value &&
+ !std::is_same<T, signed char>::value &&
+ !std::is_same<T, unsigned char>::value &&
+ !std::is_same<T, bool>::value,
+ "The requested type is not supported by the underlying random distributions from std" );
return GeneratorWrapper<T>(
Catch::Detail::make_unique<RandomIntegerGenerator<T>>(a, b, Detail::getSeed())
);