Today, I thought I'd ask a very interesting question. Consider the following code:
Now, the first row works as expected. It calls the std::uniform_int<int>(0, 4) constructor (in my case). However, I figured the second row should work as well.Code:m_Distribution = std::uniform_int<int>(0, AvailableSymbols.size() - 1); m_Distribution = (decltype(m_Distribution))(0, AvailableSymbols.size() - 1);
Unfortunately, it doesn't quite work. I'm not 100% sure why, but it calls std::uniform_int<int>(0, 9) (with 9 being a default value for the constructor).
I'm guessing it's because the compiler interprets (decltype(m_Distribution)) as (std::uniform_int<int>). That is, a C-style cast.
Still, does anyone know? And might there be a way of calling the constructor without specifying the exact type? I'd be interested in knowing.
(Btw,
doesn't compile.)Code:m_Distribution = decltype(m_Distribution)(0, AvailableSymbols.size() - 1);