Boost logo

Boost :

Subject: [boost] [any] implement reset for direct constructing (adapt to noncopyable)
From: nowake_at_[hidden]
Date: 2009-02-12 08:22:12


Hi All.

I modified boost::any to adapt noncopyable object.

The boost::any can use noncopyable object like this:
_____________________________________________________________
    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<B>(10, 20); // compile error
       test.reset<B, false>(10, 20);
       //any test2(test); // throw
       //any test2;
       //test2 = test; // throw
       BOOST_CHECK_EQUAL(any_cast<B&>(test).v1, 10);
       BOOST_CHECK_EQUAL(any_cast<B&>(test).v2, 20);
    }
_____________________________________________________________________
If you are interested in this, please see #2748 for detail.
https://svn.boost.org/trac/boost/ticket/2748

Thanks,
Nowake


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk