Ticket #4637: extra_scoped_array_constructor.patch

File extra_scoped_array_constructor.patch, 1.4 KB (added by niels_dekker, 12 years ago)
  • boost/smart_ptr/scoped_array.hpp

     
    6060#endif
    6161    }
    6262
     63    explicit scoped_array(std::size_t n) : px( n == 0 ? 0 : new T[n]() )
     64    {
     65#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
     66        boost::sp_array_constructor_hook( px );
     67#endif
     68    }
     69
    6370    ~scoped_array() // never throws
    6471    {
    6572#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
  • libs/smart_ptr/test/smart_ptr_test.cpp

     
    144144    sa.reset();
    145145    BOOST_TEST( sa.get() == 0 );
    146146
     147    std::size_t zero = 0;
     148    BOOST_TEST( boost::scoped_array<char>(zero).get() == 0 );
     149    std::size_t two = 2;
     150    boost::scoped_array<char> scoped_array_of_size_two(two);
     151    BOOST_TEST( scoped_array_of_size_two[0] == '\0' );
     152    BOOST_TEST( scoped_array_of_size_two[1] == '\0' );
     153    scoped_array_of_size_two[1] = '1';
     154    BOOST_TEST( scoped_array_of_size_two[0] == '\0' );
     155    BOOST_TEST( scoped_array_of_size_two[1] == '1' );
     156
    147157    //  test shared_ptr with a built-in type
    148158    int * ip = new int;
    149159    boost::shared_ptr<int> cp ( ip );