I have a C++ class which contains some kind of "static state" ("m_engine" in this particular case):
class RndGenerator
{
public:
static void setInitialSeed(unsigned int seed);
static unsigned int rndNumber();
...
private:
...
RndGenerator();
static std::mt19937 m_engine;
};
This class is used extensively in my project, on C++ level.
After exposing RndGenerator via Boost.Python:
class_<RndGenerator, boost::noncopyable>("RndGenerator", no_init)
.def("setInitialSeed", &RndGenerator::setInitialSeed)
.staticmethod("setInitialSeed")
.def("rndNumber", &RndGenerator::rndNumber)
.staticmethod("rndNumber")
;
I would like to have possibility to set initial seed from Python level:
RndGenerator.setInitialSeed(1234)
I would expect, that after this line all calls to RndGenerator::rndNumber(), on C++ level, would take into account just specified initial seed (1234). However this is not the case.
Is there any problem with classes containing static members exposed to Python? Or is my problem related to singleton-like nature of RndGenerator?