The C ++ standard in it in paragraph 26.5.1.1 states the following:
In this clause 26.5, the effect of creating a template is:
e) that has a template type parameter named IntType is undefined if the corresponding template argument is not qv-unqualified and is one of short , int , long , long long , unsigned short , unsigned int , unsigned long or unsigned long long .
f), which has a template type parameter named UIntType, is undefined if the corresponding template argument is not qv and is one of unsigned short , unsigned int , unsigned long or unsigned long long .
So,
std::uniform_int_distribution<char> r;
can call UB, as well as the same with unsigned char, int8_t and uint8_t.
GNU compilers allow you to create uniform_int_distribution with char , and the code above works fine. But Microsoft rightfully states :
We are trying to help custom code stay in the scope of undefined behavior by being strict rather than permissive.
Visual studio does not compile code, not with errors:
error C2338: invalid template argument for uniform_int_distribution note: see reference to class template instantiation 'std::uniform_int_distribution<uint8_t>' being compiled
What is the reason for these restrictions? Will the Committee allow instances of uniform_int_distribution with single-byte types in future versions of the language?