[Boost-bugs] [Boost C++ Libraries] #2748: [any] implement reset for direct constructing (adapt to noncopyable)

Subject: [Boost-bugs] [Boost C++ Libraries] #2748: [any] implement reset for direct constructing (adapt to noncopyable)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-02-11 14:34:30


#2748: [any] implement reset for direct constructing (adapt to noncopyable)
------------------------------------+---------------------------------------
 Reporter: nowake_at_[hidden] | Owner: nasonov
     Type: Patches | Status: new
Milestone: Boost 1.39.0 | Component: any
  Version: Boost 1.38.0 | Severity: Optimization
 Keywords: any noncopyable |
------------------------------------+---------------------------------------
 I modified boost::any to adapt noncopyable object.

 (a) add reset members to construct content directory.
 (b) modify boost::any::holder

 Sample:
  {{{
    struct A {
       A() : v() {};
       A(unsigned int value) : v(value) {};
       unsigned int v;
    };

    BOOST_AUTO_TEST_CASE(test01)
    {
       any test;
       test.reset<A>(10);
       BOOST_CHECK_EQUAL(any_cast<A>(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<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);
    }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2748>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC