Boost C++ Libraries: Ticket #2887: mersenne_twister generated copy ctor overloaded by a template ctor https://svn.boost.org/trac10/ticket/2887 <p> Compiled-generated copy constructor and assignment operator are fine, but the copy constructor is overloaded by mersenne_twister(Generator &amp; gen) { seed(gen); } even is the Generator type is mersenne_twister; </p> <pre class="wiki"> template&lt;class Generator&gt; explicit mersenne_twister(Generator &amp; gen) { seed(gen); } // compiler-generated copy ctor and assignment operator are fine </pre><p> Hence calling </p> <pre class="wiki"> boost::mt19937 rng(0); boost::mt19937 rngcopy(rng); std::cout &lt;&lt; (rng==rngcopy) &lt;&lt; std::endl; </pre><p> yields "false". </p> <p> Maybe a boost::disable_if&lt;boost::is_same&lt;mersenne_twister,Generator&gt; &gt; solves the problem. </p> <p> See also the workaround made in default constructor of boost::pass_through_engine to avoid matching Generator &amp; constructor </p> <p> S. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2887 Trac 1.4.3 corlay@… Thu, 26 Mar 2009 15:34:56 GMT <link>https://svn.boost.org/trac10/ticket/2887#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2887#comment:1</guid> <description> <p> In mersenne_twister.hpp, replacing </p> <pre class="wiki">template&lt;class Generator&gt; explicit mersenne_twister(Generator &amp; gen) { seed(gen); } </pre><p> by </p> <pre class="wiki"> template&lt;class Generator&gt; explicit mersenne_twister(Generator &amp; gen, typename disable_if&lt; is_same&lt;Generator,mersenne_twister&gt;,int &gt;::type = 0) { seed(gen); } </pre><p> and add includes </p> <pre class="wiki">#include &lt;boost/utility/enable_if.hpp&gt; #include &lt;boost/type_traits/is_same.hpp&gt; </pre><p> seems to solve it. No need to handle with the const case. </p> <p> <em>Then, one has to do it for other generators</em> and, in pass_through_engine.hpp, one can then replace </p> <pre class="wiki"> explicit pass_through_engine(UniformRandomNumberGenerator rng) // make argument an rvalue to avoid matching Generator&amp; constructor : _rng(static_cast&lt;typename helper_type::rvalue_type&gt;(rng)) { } </pre><p> by </p> <pre class="wiki"> explicit pass_through_engine(UniformRandomNumberGenerator rng) : _rng(rng) { } </pre><p> . </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 28 Mar 2009 10:08:29 GMT</pubDate> <title>keywords, summary changed https://svn.boost.org/trac10/ticket/2887#comment:2 https://svn.boost.org/trac10/ticket/2887#comment:2 <ul> <li><strong>keywords</strong> Copy ctor Bug added; boost::random removed </li> <li><strong>summary</strong> <span class="trac-field-old">boost::mersenne_twister copy constructor</span> → <span class="trac-field-new">mersenne_twister generated copy ctor overloaded by a template ctor</span> </li> </ul> Ticket corlay@… Tue, 31 Mar 2009 16:13:08 GMT attachment set https://svn.boost.org/trac10/ticket/2887 https://svn.boost.org/trac10/ticket/2887 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">patchfile.patch</span> </li> </ul> <p> unified diff for the proposed correction </p> Ticket Steven Watanabe Sat, 06 Jun 2009 19:41:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2887#comment:3 https://svn.boost.org/trac10/ticket/2887#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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/53699" title="Fix overload resolution for generator constructors/seed. Fixes #351. ...">[53699]</a>) Fix overload resolution for generator constructors/seed. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/351" title="#351: Bugs: Diff in state of mersenne_twister gen between GCC3.41 &amp; CW9 (closed: fixed)">#351</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2424" title="#2424: Bugs: unsigned int causes error in seed() without static_cast (closed: fixed)">#2424</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2887" title="#2887: Bugs: mersenne_twister generated copy ctor overloaded by a template ctor (closed: fixed)">#2887</a> </p> Ticket