Skip to content

Commit

Permalink
Add full set of constraints to random integral generator
Browse files Browse the repository at this point in the history
Related to #2433
  • Loading branch information
horenmar committed Jun 2, 2022
1 parent 9e44593 commit 4142e69
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/catch2/generators/catch_generators_random.hpp
Expand Up @@ -65,12 +65,17 @@ class RandomIntegerGenerator final : public IGenerator<Integer> {
}
};

// 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())
);
Expand Down

0 comments on commit 4142e69

Please sign in to comment.