mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-04 19:51:02 +02:00
Compare commits
17 Commits
boost-1.76
...
boost-1.78
Author | SHA1 | Date | |
---|---|---|---|
|
8f40bff2f6 | ||
|
1ef8f4e72d | ||
|
f651a49d96 | ||
|
598314b8e1 | ||
|
72221d1da0 | ||
|
2cbeb5b185 | ||
|
67e657c228 | ||
|
eba3cf92e7 | ||
|
8340a13539 | ||
|
098d0f4ce3 | ||
|
fec5fb97c8 | ||
|
b52d7548b3 | ||
|
594c7485a5 | ||
|
d751041fb9 | ||
|
d41546ddce | ||
|
f3424e74e8 | ||
|
0eee7efd54 |
71
.github/workflows/ci.yml
vendored
71
.github/workflows/ci.yml
vendored
@@ -17,24 +17,17 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: gcc-4.7
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: g++-4.7
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: g++-4.8
|
||||
- toolset: gcc-4.9
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: g++-4.9
|
||||
- toolset: gcc-5
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "03,11,14,17"
|
||||
@@ -42,51 +35,38 @@ jobs:
|
||||
- toolset: gcc-8
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
install: g++-8
|
||||
- toolset: gcc-9
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
os: ubuntu-20.04
|
||||
- toolset: gcc-10
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-18.04
|
||||
- toolset: clang
|
||||
compiler: clang++-3.5
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.5
|
||||
- toolset: clang
|
||||
compiler: clang++-3.6
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.6
|
||||
- toolset: clang
|
||||
compiler: clang++-3.7
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.7
|
||||
- toolset: clang
|
||||
compiler: clang++-3.8
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.8
|
||||
os: ubuntu-20.04
|
||||
install: g++-10
|
||||
- toolset: gcc-11
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: g++-11
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-16.04
|
||||
os: ubuntu-18.04
|
||||
install: clang-5.0
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-18.04
|
||||
install: clang-6.0
|
||||
- toolset: clang
|
||||
compiler: clang++-7
|
||||
cxxstd: "03,11,14,17"
|
||||
@@ -94,16 +74,29 @@ jobs:
|
||||
install: clang-7
|
||||
- toolset: clang
|
||||
compiler: clang++-8
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
cxxstd: "03,11,14,17"
|
||||
os: ubuntu-20.04
|
||||
install: clang-8
|
||||
- toolset: clang
|
||||
compiler: clang++-9
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-9
|
||||
- toolset: clang
|
||||
compiler: clang++-10
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-10
|
||||
- toolset: clang
|
||||
compiler: clang++-11
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-11
|
||||
- toolset: clang
|
||||
compiler: clang++-12
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-12
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: macos-10.15
|
||||
@@ -162,6 +155,10 @@ jobs:
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.3
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: gcc
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
addrmd: 64
|
||||
|
@@ -160,6 +160,7 @@ matrix:
|
||||
script:
|
||||
- mkdir __build__ && cd __build__
|
||||
- cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=smart_ptr -DBUILD_TESTING=ON ..
|
||||
- cmake --build . --target tests -- -k
|
||||
- ctest --output-on-failure -R boost_smart_ptr
|
||||
|
||||
- os: linux
|
||||
|
@@ -14,6 +14,8 @@ Greg Colvin, Beman Dawes, Peter Dimov, Glen Fernandes
|
||||
:idprefix:
|
||||
:listing-caption: Code Example
|
||||
:docinfo: private-footer
|
||||
:source-highlighter: rouge
|
||||
:source-language: c++
|
||||
|
||||
:leveloffset: +1
|
||||
|
||||
|
@@ -387,7 +387,7 @@ public:
|
||||
{
|
||||
typedef typename sp_convert_reference<D>::type D2;
|
||||
|
||||
D2 d2( r.get_deleter() );
|
||||
D2 d2( static_cast<D&&>( r.get_deleter() ) );
|
||||
pi_ = new sp_counted_impl_pd< typename std::unique_ptr<Y, D>::pointer, D2 >( r.get(), d2 );
|
||||
|
||||
#ifdef BOOST_NO_EXCEPTIONS
|
||||
|
@@ -145,7 +145,7 @@ template<class P, class D> class BOOST_SYMBOL_VISIBLE sp_counted_impl_pd: public
|
||||
private:
|
||||
|
||||
P ptr; // copy constructor must not throw
|
||||
D del; // copy constructor must not throw
|
||||
D del; // copy/move constructor must not throw
|
||||
|
||||
sp_counted_impl_pd( sp_counted_impl_pd const & );
|
||||
sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
|
||||
@@ -156,10 +156,20 @@ public:
|
||||
|
||||
// pre: d(p) must not throw
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
sp_counted_impl_pd( P p, D & d ): ptr( p ), del( static_cast< D&& >( d ) )
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
sp_counted_impl_pd( P p, D & d ): ptr( p ), del( d )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
sp_counted_impl_pd( P p ): ptr( p ), del()
|
||||
{
|
||||
}
|
||||
@@ -218,7 +228,7 @@ template<class P, class D, class A> class BOOST_SYMBOL_VISIBLE sp_counted_impl_p
|
||||
private:
|
||||
|
||||
P p_; // copy constructor must not throw
|
||||
D d_; // copy constructor must not throw
|
||||
D d_; // copy/move constructor must not throw
|
||||
A a_; // copy constructor must not throw
|
||||
|
||||
sp_counted_impl_pda( sp_counted_impl_pda const & );
|
||||
@@ -230,10 +240,20 @@ public:
|
||||
|
||||
// pre: d( p ) must not throw
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
sp_counted_impl_pda( P p, D & d, A a ): p_( p ), d_( static_cast< D&& >( d ) ), a_( a )
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
sp_counted_impl_pda( P p, D & d, A a ): p_( p ), d_( d ), a_( a )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
sp_counted_impl_pda( P p, A a ): p_( p ), d_( a ), a_( a )
|
||||
{
|
||||
}
|
||||
|
@@ -374,39 +374,81 @@ public:
|
||||
}
|
||||
|
||||
//
|
||||
// Requirements: D's copy constructor must not throw
|
||||
// Requirements: D's copy/move constructors must not throw
|
||||
//
|
||||
// shared_ptr will release p by calling d(p)
|
||||
//
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class Y, class D> shared_ptr( Y * p, D d ): px( p ), pn( p, static_cast< D&& >( d ) )
|
||||
{
|
||||
boost::detail::sp_deleter_construct( this, p );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class Y, class D> shared_ptr( Y * p, D d ): px( p ), pn( p, d )
|
||||
{
|
||||
boost::detail::sp_deleter_construct( this, p );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class D> shared_ptr( boost::detail::sp_nullptr_t p, D d ): px( p ), pn( p, static_cast< D&& >( d ) )
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class D> shared_ptr( boost::detail::sp_nullptr_t p, D d ): px( p ), pn( p, d )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// As above, but with allocator. A's copy constructor shall not throw.
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, static_cast< D&& >( d ), a )
|
||||
{
|
||||
boost::detail::sp_deleter_construct( this, p );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
|
||||
{
|
||||
boost::detail::sp_deleter_construct( this, p );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class D, class A> shared_ptr( boost::detail::sp_nullptr_t p, D d, A a ): px( p ), pn( p, static_cast< D&& >( d ), a )
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class D, class A> shared_ptr( boost::detail::sp_nullptr_t p, D d, A a ): px( p ), pn( p, d, a )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// generated copy constructor, destructor are fine...
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
@@ -693,6 +735,20 @@ public:
|
||||
this_type( p ).swap( *this );
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
template<class Y, class D> void reset( Y * p, D d )
|
||||
{
|
||||
this_type( p, static_cast< D&& >( d ) ).swap( *this );
|
||||
}
|
||||
|
||||
template<class Y, class D, class A> void reset( Y * p, D d, A a )
|
||||
{
|
||||
this_type( p, static_cast< D&& >( d ), a ).swap( *this );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class Y, class D> void reset( Y * p, D d )
|
||||
{
|
||||
this_type( p, d ).swap( *this );
|
||||
@@ -703,6 +759,8 @@ public:
|
||||
this_type( p, d, a ).swap( *this );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class Y> void reset( shared_ptr<Y> const & r, element_type * p ) BOOST_SP_NOEXCEPT
|
||||
{
|
||||
this_type( r, p ).swap( *this );
|
||||
|
11
test/Jamfile
11
test/Jamfile
@@ -81,7 +81,7 @@ run sp_recursive_assign_rv_test.cpp ;
|
||||
run sp_recursive_assign2_rv_test.cpp ;
|
||||
|
||||
compile-fail auto_ptr_lv_fail.cpp
|
||||
: <toolset>gcc-4.4.7:<build>no ;
|
||||
: <toolset>gcc-4.4.7:<build>no <toolset>gcc-4.4:<build>no ;
|
||||
|
||||
run atomic_count_test2.cpp ;
|
||||
run sp_typeinfo_test.cpp ;
|
||||
@@ -331,9 +331,9 @@ run weak_ptr_alias_move_test.cpp ;
|
||||
|
||||
run sp_typeinfo_test.cpp : : : <rtti>off : sp_typeinfo_test_no_rtti ;
|
||||
|
||||
run get_deleter_test.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test_no_rtti ;
|
||||
run get_deleter_test2.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test2_no_rtti ;
|
||||
run get_deleter_test3.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no : get_deleter_test3_no_rtti ;
|
||||
run get_deleter_test.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no <toolset>gcc-4.4,<cxxstd>0x:<build>no : get_deleter_test_no_rtti ;
|
||||
run get_deleter_test2.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no <toolset>gcc-4.4,<cxxstd>0x:<build>no : get_deleter_test2_no_rtti ;
|
||||
run get_deleter_test3.cpp : : : <rtti>off <toolset>gcc-4.4.7,<cxxstd>0x:<build>no <toolset>gcc-4.4,<cxxstd>0x:<build>no : get_deleter_test3_no_rtti ;
|
||||
|
||||
run shared_from_test.cpp ;
|
||||
run weak_from_test.cpp ;
|
||||
@@ -408,3 +408,6 @@ run wp_unordered_test.cpp ;
|
||||
|
||||
run owner_hash_test.cpp ;
|
||||
run sp_unordered_test.cpp ;
|
||||
|
||||
run sp_unique_ptr_test2.cpp ;
|
||||
run sp_move_only_deleter.cpp ;
|
||||
|
153
test/sp_move_only_deleter.cpp
Normal file
153
test/sp_move_only_deleter.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_RVALUE_REFERENCES is defined")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
struct Y
|
||||
{
|
||||
static int instances;
|
||||
|
||||
bool deleted_;
|
||||
|
||||
Y(): deleted_( false )
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~Y()
|
||||
{
|
||||
BOOST_TEST( deleted_ );
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Y( Y const & );
|
||||
Y & operator=( Y const & );
|
||||
};
|
||||
|
||||
int Y::instances = 0;
|
||||
|
||||
struct YD
|
||||
{
|
||||
bool moved_;
|
||||
|
||||
YD(): moved_( false )
|
||||
{
|
||||
}
|
||||
|
||||
YD( YD&& r ): moved_( false )
|
||||
{
|
||||
r.moved_ = true;
|
||||
}
|
||||
|
||||
void operator()( Y* p ) const
|
||||
{
|
||||
BOOST_TEST( !moved_ );
|
||||
|
||||
if( p )
|
||||
{
|
||||
p->deleted_ = true;
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
YD( YD const & );
|
||||
YD & operator=( YD const & );
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
|
||||
{
|
||||
YD del;
|
||||
boost::shared_ptr<Y> p( new Y, std::move( del ) );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( del.moved_ );
|
||||
|
||||
p.reset( new Y, YD() );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
p = boost::shared_ptr<Y>( new Y, YD() );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
YD del2;
|
||||
p.reset( new Y, std::move( del2 ) );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( del2.moved_ );
|
||||
|
||||
p.reset();
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
YD del;
|
||||
boost::shared_ptr<Y> p( new Y, std::move( del ), std::allocator<Y>() );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( del.moved_ );
|
||||
|
||||
p.reset( new Y, YD(), std::allocator<Y>() );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
p = boost::shared_ptr<Y>( new Y, YD(), std::allocator<Y>() );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
YD del2;
|
||||
p.reset( new Y, std::move( del2 ), std::allocator<Y>() );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( del2.moved_ );
|
||||
|
||||
p.reset();
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
{
|
||||
boost::shared_ptr<Y> p( nullptr, YD() );
|
||||
|
||||
YD del;
|
||||
p = boost::shared_ptr<Y>( nullptr, std::move( del ) );
|
||||
|
||||
BOOST_TEST( del.moved_ );
|
||||
}
|
||||
|
||||
{
|
||||
boost::shared_ptr<Y> p( nullptr, YD(), std::allocator<Y>() );
|
||||
|
||||
YD del;
|
||||
p = boost::shared_ptr<Y>( nullptr, std::move( del ), std::allocator<Y>() );
|
||||
|
||||
BOOST_TEST( del.moved_ );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
153
test/sp_unique_ptr_test2.cpp
Normal file
153
test/sp_unique_ptr_test2.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#if defined( BOOST_NO_CXX11_SMART_PTR )
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_SMART_PTR is defined")
|
||||
int main() {}
|
||||
|
||||
#elif defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because BOOST_NO_CXX11_RVALUE_REFERENCES is defined")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC < 1700
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because msvc-10.0 unique_ptr doesn't support move-only deleters")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
struct Y
|
||||
{
|
||||
static int instances;
|
||||
|
||||
bool deleted_;
|
||||
|
||||
Y(): deleted_( false )
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~Y()
|
||||
{
|
||||
BOOST_TEST( deleted_ );
|
||||
--instances;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Y( Y const & );
|
||||
Y & operator=( Y const & );
|
||||
};
|
||||
|
||||
int Y::instances = 0;
|
||||
|
||||
struct YD
|
||||
{
|
||||
bool moved_;
|
||||
|
||||
YD(): moved_( false )
|
||||
{
|
||||
}
|
||||
|
||||
YD( YD&& r ): moved_( false )
|
||||
{
|
||||
r.moved_ = true;
|
||||
}
|
||||
|
||||
void operator()( Y* p ) const
|
||||
{
|
||||
BOOST_TEST( !moved_ );
|
||||
|
||||
if( p )
|
||||
{
|
||||
p->deleted_ = true;
|
||||
delete p;
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR( "YD::operator()(0) called" );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
YD( YD const & );
|
||||
YD & operator=( YD const & );
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
|
||||
{
|
||||
std::unique_ptr<Y, YD> p( new Y );
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
boost::shared_ptr<Y> p2( std::move( p ) );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.get_deleter().moved_ );
|
||||
|
||||
p2.reset();
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<Y, YD> p( new Y );
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
boost::shared_ptr<void> p2( std::move( p ) );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.get_deleter().moved_ );
|
||||
|
||||
p2.reset();
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<Y, YD> p( new Y );
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
boost::shared_ptr<Y> p2;
|
||||
p2 = std::move( p );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.get_deleter().moved_ );
|
||||
|
||||
p2.reset();
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<Y, YD> p( new Y );
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
|
||||
boost::shared_ptr<void> p2( new int(0) );
|
||||
p2 = std::move( p );
|
||||
|
||||
BOOST_TEST( Y::instances == 1 );
|
||||
BOOST_TEST( p.get() == 0 );
|
||||
BOOST_TEST( p.get_deleter().moved_ );
|
||||
|
||||
p2.reset();
|
||||
BOOST_TEST( Y::instances == 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user