Opened 10 years ago
Closed 10 years ago
#7550 closed Bugs (invalid)
Vector of variate generators cannot be populated
Reported by: | Owned by: | No-Maintainer | |
---|---|---|---|
Milestone: | To Be Determined | Component: | random |
Version: | Boost 1.48.0 | Severity: | Problem |
Keywords: | vector, STL, variate generator | Cc: |
Description
As in the title, it is impossible to populate a vector of variate generators. I tried to combine Mersenne Twister with uniform_real distribution. The problem appears when using assignment operator. There is no problem when I try to populate STL list with the same objects. The same issue appears for fixed seed. I observed that simple assignment of one variate generator to another one is also impossible. Please find my code snippet below.
boost::mt19937 rng(static_cast<unsigned int>(time(0))); std::vector<boost::uniform_real<> > unifRealDistrVector; typedef boost::variate_generator<boost::mt19937&, boost::uniform_real<> > unifRealVarGen; std::vector<unifRealVarGen> unifRealVarGenVector; //std::list<unifRealVarGen> unifRealVarGenList; for (unsigned int iter = 0; iter < 6; iter++) { boost::uniform_real<> unifRealDistr(0.0, iter); unifRealVarGen varGen(rng, unifRealDistr); unifRealVarGenVector.push_back(varGen); //unifRealVarGenList.push_back(varGen); }
Error message I received is:
/usr/include/boost/random/detail/pass_through_engine.hpp:26:7: error: non-static reference member ‘boost::random::mersenne_twister<unsigned int, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18, 3346425566u>& boost::random::detail::pass_through_engine<boost::random::mersenne_twister<unsigned int, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18, 3346425566u>&>::_rng’, can’t use default assignment operator
I use Cross G++ Compiler 4.6.3 on Ubuntu. I am still learning Boost.Random library. Please correct me if such an operation does not make much sense. Thanks in advance.
Change History (3)
follow-up: 2 comment:1 by , 10 years ago
comment:2 by , 10 years ago
Thank you for pointing it out. I should have read the variate_generator template description more carefully.
Replying to steven_watanabe:
The problem is that a variate_generator containing a reference is not Assignable. In C++03, the element type of a container must be Assignable (23.1). Use a pointer instead:
variate_generator<mt19937*, uniform_real<> >Note: The requirement of assignment is relaxed in C++11.
comment:3 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
The problem is that a variate_generator containing a reference is not Assignable. In C++03, the element type of a container must be Assignable (23.1). Use a pointer instead:
Note: The requirement of assignment is relaxed in C++11.