jeudi 2 juillet 2015

C++11 random number generator UIntType contradiction

Section 26.5.1.1 paragraph 1 of the C++11 standard (N3242) says:

Throughout this subclause 26.5, the effect of instantiating a template:

[...]

f) that has a template type parameter named UIntType is undefined unless the corresponding template argument is cv-unqualified and is one of unsigned short, unsigned int, unsigned long, or unsigned long long.

And it defines the linear congruential generator in 26.5.3.1. The definition of the class starts like this:

template<class UIntType, UIntType a, UIntType c, UIntType m>
class linear_congruential_engine

minstd_rand0 seems to violate this restriction:

typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
    minstd_rand0;

As it uses uint_fast32_t (which isn't guaranteed to be one of unsigned short, unsigned int, unsigned long, or unsigned long long) in minstd_rand0 for a template parameter named UIntType, it appears to have undefined effect to #include <random>, or at least to use minstd_rand0. This problem applies to other predefined RNGs as well, and it does not appear to be fixed in C++14.

My questions are:

  • Is this really a contradiction (or rather an extreme amount of undefined behaviour), or have I missed something?
  • Has this been mentioned in a defect report?

Aucun commentaire:

Enregistrer un commentaire