mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-04 19:51:02 +02:00
Compare commits
5 Commits
boost-1.76
...
feature/mo
Author | SHA1 | Date | |
---|---|---|---|
|
098d0f4ce3 | ||
|
d751041fb9 | ||
|
d41546ddce | ||
|
f3424e74e8 | ||
|
0eee7efd54 |
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@@ -42,6 +42,7 @@ 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
|
||||
@@ -50,7 +51,7 @@ jobs:
|
||||
os: ubuntu-18.04
|
||||
- toolset: clang
|
||||
compiler: clang++-3.5
|
||||
cxxstd: "03,11,14"
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-16.04
|
||||
install: clang-3.5
|
||||
- toolset: clang
|
||||
@@ -87,6 +88,7 @@ jobs:
|
||||
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"
|
||||
@@ -96,6 +98,7 @@ jobs:
|
||||
compiler: clang++-8
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: clang-8
|
||||
- toolset: clang
|
||||
compiler: clang++-9
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
@@ -104,6 +107,10 @@ jobs:
|
||||
compiler: clang++-10
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
- toolset: clang
|
||||
compiler: clang++-11
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: macos-10.15
|
||||
|
@@ -387,8 +387,8 @@ public:
|
||||
{
|
||||
typedef typename sp_convert_reference<D>::type D2;
|
||||
|
||||
D2 d2( r.get_deleter() );
|
||||
pi_ = new sp_counted_impl_pd< typename std::unique_ptr<Y, D>::pointer, D2 >( r.get(), d2 );
|
||||
D2 d2( static_cast<D&&>( r.get_deleter() ) );
|
||||
pi_ = new sp_counted_impl_pd< typename std::unique_ptr<Y, D>::pointer, D2 >( r.get(), static_cast< D2&& >( 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 & );
|
||||
@@ -160,6 +160,14 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
|
||||
sp_counted_impl_pd( P p, D && d ): ptr( p ), del( static_cast< D&& >( d ) )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
sp_counted_impl_pd( P p ): ptr( p ), del()
|
||||
{
|
||||
}
|
||||
|
@@ -408,3 +408,5 @@ run wp_unordered_test.cpp ;
|
||||
|
||||
run owner_hash_test.cpp ;
|
||||
run sp_unordered_test.cpp ;
|
||||
|
||||
run sp_unique_ptr_test2.cpp ;
|
||||
|
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