Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ and this project adheres to
[#733](https://github.com/pdidev/pdi/issues/733)

#### Fixed
* Fix [#737](https://github.com/pdidev/pdi/issues/737) as random_init
from integral did not match IntType used (while bool and char remain
intentionally unsupported)

#### Security

Expand Down
11 changes: 10 additions & 1 deletion pdi/include/pdi/testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
*/

#include <algorithm>
#include <concepts>
#include <filesystem>
#include <limits>
#include <random>
#include <ranges>
#include <type_traits>
Expand Down Expand Up @@ -99,11 +101,18 @@ concept buildable_from = std::constructible_from<T, G&> && requires(G& g) {
};
};

/** Bridge the gap between integral and IntType, by disabling bool and char.
*/
template <class T>
concept distribution_safe_integral
= std::same_as<T, short> || std::same_as<T, unsigned short> || std::same_as<T, int> || std::same_as<T, unsigned int> || std::same_as<T, long>
|| std::same_as<T, unsigned long> || std::same_as<T, long long> || std::same_as<T, unsigned long long>;

/** initialize an integral value with uniformly distributed values from the provided generator
* \param gen the (pseudo)random generator
* \param t the value to initialize
*/
static inline void random_init(std::uniform_random_bit_generator auto& gen, std::integral auto& t)
static inline void random_init(std::uniform_random_bit_generator auto& gen, distribution_safe_integral auto& t)
{
using T = std::remove_reference_t<decltype(t)>;
t = std::uniform_int_distribution<T>(std::numeric_limits<T>::min())(gen);
Expand Down
Loading