Boost C++ Libraries: Ticket #2748: [any] implement reset for direct constructing (adapt to noncopyable) https://svn.boost.org/trac10/ticket/2748 <p> I modified boost::any to adapt noncopyable object. </p> <p> (a) add reset members to construct content directory. (b) modify boost::any::holder </p> <p> Sample: </p> <pre class="wiki"> struct A { A() : v() {}; A(unsigned int value) : v(value) {}; unsigned int v; }; BOOST_AUTO_TEST_CASE(test01) { any test; test.reset&lt;A&gt;(10); BOOST_CHECK_EQUAL(any_cast&lt;A&gt;(test).v, 10); test.reset(); BOOST_CHECK_EQUAL(test.empty(), true); } struct B : boost::noncopyable { B() : v1(), v2() {}; B(unsigned int value1, unsigned int value2) : v1(value1) ,v2(value2) {}; unsigned int v1, v2; }; BOOST_AUTO_TEST_CASE(test02) { any test; //test = B(); // compile error //test.reset&lt;B&gt;(10, 20); // compile error test.reset&lt;B, false&gt;(10, 20); //any test2(test); // throw any test2; //test2 = test; // throw BOOST_CHECK_EQUAL(any_cast&lt;B&amp;&gt;(test).v1, 10); BOOST_CHECK_EQUAL(any_cast&lt;B&amp;&gt;(test).v2, 20); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2748 Trac 1.4.3 nowake@… Wed, 11 Feb 2009 14:37:22 GMT attachment set https://svn.boost.org/trac10/ticket/2748 https://svn.boost.org/trac10/ticket/2748 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">any.hpp</span> </li> </ul> <p> modified boost::any </p> Ticket anonymous Sun, 13 Sep 2009 19:30:37 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2748#comment:1 https://svn.boost.org/trac10/ticket/2748#comment:1 <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">wontfix</span> </li> </ul> <p> I think that a better and simpler approach for storing noncopyable objects is any_cast transparency to shared pointers. For instance: </p> <pre class="wiki">any p(shared_ptr&lt;X&gt;(new X)); any_cast&lt;X&amp;&gt;(p); // doesn't throw </pre><p> Alex </p> Ticket nasonov Sun, 13 Sep 2009 22:23:30 GMT <link>https://svn.boost.org/trac10/ticket/2748#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2748#comment:2</guid> <description> <p> Anonymous who closed the bug was me. </p> </description> <category>Ticket</category> </item> </channel> </rss>