In MSVS 2019 I used to declare my distribution const. Yet in the latest MSVS2022 preview, I get an error:
error C3848: expression having type 'const std::uniform_real_distribution<double>' would lose some const-volatile qualifiers in order to call 'double std::uniform_real<_Ty>::operator ()<std::mt19937>(_Engine &)'
1> with
1> [
1> _Ty=double,
1> _Engine=std::mt19937
1> ]
If I strip the const all is fine again. Is this a MSVS2022 quirk? Or was 2019 wrong all that time?
(example from https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution)
#include <random>
#include <iostream>
int main()
{
std::random_device rd; // Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
const std::uniform_real_distribution<> dis(1.0, 2.0); // this const will break in MSVS2022
for (int n = 0; n < 10; ++n) {
// Use dis to transform the random unsigned int generated by gen into a
// double in [1, 2). Each call to dis(gen) generates a new random double
std::cout << dis(gen) << ' ';
}
std::cout << '\n';
}