Boost C++ Libraries: Ticket #7550: Vector of variate generators cannot be populated https://svn.boost.org/trac10/ticket/7550 <p> 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. </p> <pre class="wiki"> boost::mt19937 rng(static_cast&lt;unsigned int&gt;(time(0))); std::vector&lt;boost::uniform_real&lt;&gt; &gt; unifRealDistrVector; typedef boost::variate_generator&lt;boost::mt19937&amp;, boost::uniform_real&lt;&gt; &gt; unifRealVarGen; std::vector&lt;unifRealVarGen&gt; unifRealVarGenVector; //std::list&lt;unifRealVarGen&gt; unifRealVarGenList; for (unsigned int iter = 0; iter &lt; 6; iter++) { boost::uniform_real&lt;&gt; unifRealDistr(0.0, iter); unifRealVarGen varGen(rng, unifRealDistr); unifRealVarGenVector.push_back(varGen); //unifRealVarGenList.push_back(varGen); } </pre><p> Error message I received is: <br /> /usr/include/boost/random/detail/pass_through_engine.hpp:26:7: error: non-static reference member ‘boost::random::mersenne_twister&lt;unsigned int, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18, 3346425566u&gt;&amp; boost::random::detail::pass_through_engine&lt;boost::random::mersenne_twister&lt;unsigned int, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18, 3346425566u&gt;&amp;&gt;::_rng’, can’t use default assignment operator </p> <p> 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. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7550 Trac 1.4.3 Steven Watanabe Tue, 23 Oct 2012 16:55:59 GMT <link>https://svn.boost.org/trac10/ticket/7550#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7550#comment:1</guid> <description> <p> 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: </p> <pre class="wiki">variate_generator&lt;mt19937*, uniform_real&lt;&gt; &gt; </pre><p> Note: The requirement of assignment is relaxed in C++11. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 23 Oct 2012 17:19:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7550#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7550#comment:2</guid> <description> <p> Thank you for pointing it out. I should have read the variate_generator template description more carefully. </p> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7550#comment:1" title="Comment 1">steven_watanabe</a>: </p> <blockquote class="citation"> <p> 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: </p> <pre class="wiki">variate_generator&lt;mt19937*, uniform_real&lt;&gt; &gt; </pre><p> Note: The requirement of assignment is relaxed in C++11. </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Thu, 14 Feb 2013 22:38:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7550#comment:3 https://svn.boost.org/trac10/ticket/7550#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket