dimanche 31 janvier 2016

Why is a const random device not possible

I am asking me the question why:

#include <random>

struct A{

   std::random_device rd; // or any other generator std::mersenne_twister...

   void doStuff() const {
       auto v = rd();
   }

}

const A a;  
a.doStuff(); // does not work since random_device::operator() is not const...

I thought maybe the random device ca still be used when constant but it cannot be seeded again but that is not the case (internal state is obviously not mutable in std::random_device)...

I want to make class A being properly defined (doStuff() is a const method) and now I suddenly need to use mutable std::random_device rd;isnt that ugly?

Is there any reason for this design?

Aucun commentaire:

Enregistrer un commentaire