[libcxx-commits] [libcxx] [libc++] add floating point type check for uniform real distrubtion (PR #70564)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 1 15:47:20 PDT 2023


================
@@ -27,6 +28,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template<class _RealType = double>
 class _LIBCPP_TEMPLATE_VIS uniform_real_distribution
 {
+  static_assert(is_floating_point<_RealType>::value, "result_type must be floating type");
----------------
ldionne wrote:

We have a utility called `__libcpp_random_is_valid_urng` in [libcxx/include/__random/is_valid.h](https://github.com/llvm/llvm-project/blob/main/libcxx/include/__random/is_valid.h#L57-L61) -- should we instead create something similar to it and handle http://eel.is/c++draft/rand.req.genl more generally?

It seems like the restriction for `is_floating_point` is shared by many distributions. From looking at the synopsis I can find:

```
template<class RealType = double>
class uniform_real_distribution;

template<class RealType = double>
class exponential_distribution;

template<class RealType = double>
class gamma_distribution;

template<class RealType = double>
class weibull_distribution;

template<class RealType = double>
class extreme_value_distribution;

template<class RealType = double>
class normal_distribution;

template<class RealType = double>
class lognormal_distribution;

template<class RealType = double>
class chi_squared_distribution;

template<class RealType = double>
class cauchy_distribution;

template<class RealType = double>
class fisher_f_distribution;

template<class RealType = double>
class student_t_distribution;

template<class RealType = double>
class piecewise_constant_distribution;

template<class RealType = double>
class piecewise_linear_distribution;
```

https://github.com/llvm/llvm-project/pull/70564


More information about the libcxx-commits mailing list