The N3337 document defines (among others) functions for generating random numbers, like std::mt19937 or std::uniform_int_distribution.
This is an example of a code that is compileable in Visual Studio:
#include <random>
#include <iostream>
int main() {
std::mt19937 generator(200);
const std::discrete_distribution<int> distribution({41, 9, 40, 10});
for(int i = 0; i < 16; i++) {
char a = 'A' + distribution(generator);
std::cout << a;
}
std::cout << "\n";
return 0;
}
The problem is the const specifier before std::discrete_distribution. The N3337 document states that operator() of probably all distribution functions is NOT marked with const. This means it shouldn't be possible to call operator() on a const object. Yet Visual Studio doesn't have any problem with it, because in its headers the operator() method inside most distribution functions do contain the const specifier (it seems the only exception is std::normal_distribution -- they don't have const there!).
Is there a reason for Visual Studio non-conformance with the standard here?
It is a problem, because it makes code written in Visual Studio not compileable in other compilers, like GCC, which has operator() properly marked as non-const and doesn't allow the program above to be compiled.
Aucun commentaire:
Enregistrer un commentaire