Compare commits

...

22 Commits

Author SHA1 Message Date
f3279d24b4 Merge branch 'develop' 2016-05-21 22:45:34 +03:00
c87b6e8af8 Add .travis.yml 2016-05-21 22:07:23 +03:00
aaded4f85c Merge branch 'develop' 2016-05-21 20:48:54 +03:00
eb1a002e34 Create README.md 2016-05-21 19:34:15 +03:00
3304a56101 Merge branch 'develop' 2016-05-21 18:55:46 +03:00
181f38682f Add appveyor.yml. 2016-05-21 18:23:41 +03:00
5b1a8412c3 Merge branch 'develop' 2016-05-21 01:11:22 +03:00
e52905cf3c Add intrusive_ptr converting move assignment. 2016-05-17 18:43:41 +03:00
b7f99ceba6 Update intrusive_ptr_move_test with converting move construction. 2016-05-17 18:36:50 +03:00
a7ade6f062 Remove unnecessary #ifdef 2016-05-17 18:34:18 +03:00
097d2e9bf9 Merge branch 'intrusive_ptr_move' of https://github.com/jtwang83/smart_ptr into develop 2016-05-17 18:29:29 +03:00
d44a78d671 Merge branch 'develop' 2016-05-17 18:10:45 +03:00
582eb63cb3 Merge pull request #18 from joachim-faulhaber/smart_ptr_patches_1_59_0
Warning fixes: Conversion and unused parameter warnings
2016-05-17 18:07:32 +03:00
181b449a57 Merge branch 'develop' 2016-05-17 18:01:36 +03:00
da8de3e95b Merge pull request #19 from Lastique/patch-4
Make the default  intrusive_ptr constructor constexpr
2016-05-17 17:59:10 +03:00
6c27833099 Merge branch 'develop' 2016-05-17 17:46:15 +03:00
522f6c1869 Add more aliasing move test cases, add alias move reset 2016-04-13 14:31:43 +03:00
cd8de9d4a6 Merge branch 'move-alias' of https://github.com/uecasm/smart_ptr into develop 2016-04-13 13:29:50 +03:00
05d5a4e9a0 Added shared_ptr aliasing move constructor.
Signed-off-by: Gavin Lambert <github@mirality.co.nz>
2015-10-12 18:19:22 +13:00
970a179ac2 Make the default constructor constexpr 2015-10-05 18:24:52 +03:00
fd543d3292 Warning fixes: Conversion and unused parameter warnings 2015-09-24 14:53:40 +02:00
334654de06 intrusive_ptr: add converting ctor for intrusive_ptr<U> with move semantics. Analagous to
template <class U> intrusive_ptr(intrusive_ptr<U> const&)
2015-03-15 20:17:55 -04:00
11 changed files with 450 additions and 4 deletions

48
.travis.yml Normal file
View File

@ -0,0 +1,48 @@
# Copyright 2016 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
language: cpp
sudo: false
os:
- linux
- osx
branches:
only:
- master
- develop
install:
- git clone -b $TRAVIS_BRANCH https://github.com/boostorg/boost.git boost
- cd boost
- git submodule init libs/align
- git submodule init libs/assert
- git submodule init libs/atomic
- git submodule init libs/config
- git submodule init libs/core
- git submodule init libs/detail
- git submodule init libs/functional
- git submodule init libs/integer
- git submodule init libs/move
- git submodule init libs/predef
- git submodule init libs/preprocessor
- git submodule init libs/smart_ptr
- git submodule init libs/static_assert
- git submodule init libs/throw_exception
- git submodule init libs/type_traits
- git submodule init tools/build
- git submodule init tools/inspect
- git submodule update
- cd libs/smart_ptr
- git checkout -q $TRAVIS_COMMIT
- cd ../..
- ./bootstrap.sh
- ./b2 headers
script:
- TOOLSET=gcc,clang
- if [ $TRAVIS_OS_NAME == osx ]; then TOOLSET=clang; fi
- ./b2 libs/smart_ptr/test toolset=$TOOLSET

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# Boost.SmartPtr
Branch | Travis | Appveyor
---------|--------|---------
Develop | [![Build Status](https://travis-ci.org/boostorg/smart_ptr.svg?branch=develop)](https://travis-ci.org/boostorg/smart_ptr) | [![Build Status](https://ci.appveyor.com/api/projects/status/github/boostorg/smart_ptr?branch=develop&svg=true)](https://ci.appveyor.com/project/pdimov/smart_ptr)
Master | [![Build Status](https://travis-ci.org/boostorg/smart_ptr.svg?branch=master)](https://travis-ci.org/boostorg/smart_ptr) | [![Build Status](https://ci.appveyor.com/api/projects/status/github/boostorg/smart_ptr?branch=master&svg=true)](https://ci.appveyor.com/project/pdimov/smart_ptr)

44
appveyor.yml Normal file
View File

@ -0,0 +1,44 @@
# Copyright 2016 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
version: 1.0.{build}-{branch}
shallow_clone: true
branches:
only:
- master
- develop
install:
- git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost
- cd boost
- git submodule init libs/align
- git submodule init libs/assert
- git submodule init libs/atomic
- git submodule init libs/config
- git submodule init libs/core
- git submodule init libs/detail
- git submodule init libs/functional
- git submodule init libs/integer
- git submodule init libs/move
- git submodule init libs/predef
- git submodule init libs/preprocessor
- git submodule init libs/smart_ptr
- git submodule init libs/static_assert
- git submodule init libs/throw_exception
- git submodule init libs/type_traits
- git submodule init tools/build
- git submodule init tools/inspect
- git submodule update
- cd libs\smart_ptr
- git checkout -q %APPVEYOR_REPO_COMMIT%
- cd ..\..
- bootstrap
- b2 headers
build: off
test_script:
- b2 libs/smart_ptr/test toolset=msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0

View File

@ -104,7 +104,7 @@ private:
}
// Note: invoked automatically by shared_ptr; do not call
template<class X, class Y> void _internal_accept_owner( shared_ptr<X> * ppx, Y * py ) const
template<class X, class Y> void _internal_accept_owner( shared_ptr<X> * ppx, Y * ) const
{
BOOST_ASSERT( ppx != 0 );

View File

@ -59,7 +59,7 @@ public:
typedef T element_type;
intrusive_ptr() BOOST_NOEXCEPT : px( 0 )
BOOST_CONSTEXPR intrusive_ptr() BOOST_NOEXCEPT : px( 0 )
{
}
@ -122,6 +122,30 @@ public:
return *this;
}
template<class U> friend class intrusive_ptr;
template<class U>
#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
intrusive_ptr(intrusive_ptr<U> && rhs, typename boost::detail::sp_enable_if_convertible<U,T>::type = boost::detail::sp_empty())
#else
intrusive_ptr(intrusive_ptr<U> && rhs)
#endif
: px( rhs.px )
{
rhs.px = 0;
}
template<class U>
intrusive_ptr & operator=(intrusive_ptr<U> && rhs) BOOST_NOEXCEPT
{
this_type( static_cast< intrusive_ptr<U> && >( rhs ) ).swap(*this);
return *this;
}
#endif
intrusive_ptr & operator=(intrusive_ptr const & rhs)

View File

@ -83,7 +83,7 @@ struct thread_safe_counter
static unsigned int decrement(boost::detail::atomic_count& counter) BOOST_NOEXCEPT
{
return --counter;
return static_cast< unsigned int >(--counter);
}
};

View File

@ -642,6 +642,14 @@ public:
return *this;
}
// aliasing move
template<class Y>
shared_ptr( shared_ptr<Y> && r, element_type * p ) BOOST_NOEXCEPT : px( p ), pn()
{
pn.swap( r.pn );
r.px = 0;
}
#endif
#if !defined( BOOST_NO_CXX11_NULLPTR )
@ -679,7 +687,16 @@ public:
{
this_type( r, p ).swap( *this );
}
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
template<class Y> void reset( shared_ptr<Y> && r, element_type * p )
{
this_type( static_cast< shared_ptr<Y> && >( r ), p ).swap( *this );
}
#endif
// never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)
typename boost::detail::sp_dereference< T >::type operator* () const
{

View File

@ -139,6 +139,8 @@ void bad()
template&lt;class Y&gt; <a href="#aliasing_constructor" >shared_ptr</a>(shared_ptr&lt;Y&gt; const &amp; r, element_type * p); // never throws
template&lt;class Y&gt; <a href="#aliasing_move_constructor" >shared_ptr</a>(shared_ptr&lt;Y&gt; &amp;&amp; r, element_type * p); // never throws
template&lt;class Y&gt; explicit <a href="#weak_ptr_constructor" >shared_ptr</a>(<a href="weak_ptr.htm" >weak_ptr</a>&lt;Y&gt; const &amp; r);
template&lt;class Y&gt; explicit <a href="#auto_ptr_constructor" >shared_ptr</a>(std::auto_ptr&lt;Y&gt; &amp; r);
@ -352,6 +354,16 @@ template&lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt; &amp;&amp; r); // never t
<p><b>Postconditions:</b> <code>get() == p &amp;&amp; use_count() == r.use_count()</code>.</p>
<p><b>Throws:</b> nothing.</p>
</blockquote>
<h3 id="aliasing_move_constructor">aliasing move constructor</h3>
<pre>template&lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt; &amp;&amp; r, element_type * p); // never throws</pre>
<blockquote>
<p>
<b>Effects:</b> Move-constructs a <code>shared_ptr</code> from <code>r</code>, while
storing <code>p</code> instead.
</p>
<p><b>Postconditions:</b> <code>get() == p</code> and <code>use_count()</code> equals the old count of <code>r</code>. <code>r</code> is <em>empty</em> and <code>r.get() == 0</code>.</p>
<p><b>Throws:</b> nothing.</p>
</blockquote>
<h3 id="weak_ptr_constructor">weak_ptr constructor</h3>
<pre>template&lt;class Y&gt; explicit shared_ptr(<a href="weak_ptr.htm" >weak_ptr</a>&lt;Y&gt; const &amp; r);</pre>
<blockquote>

View File

@ -34,6 +34,7 @@ import testing ;
[ run shared_ptr_alias_test.cpp ]
[ run shared_ptr_rv_test.cpp ]
[ run shared_ptr_move_test.cpp ]
[ run shared_ptr_alias_move_test.cpp ]
[ compile-fail shared_ptr_pv_fail.cpp ]
[ run sp_unary_addr_test.cpp ]
[ compile-fail scoped_ptr_eq_fail.cpp ]

View File

@ -143,6 +143,18 @@ int main()
BOOST_TEST( N::base::instances == 0 );
}
{
boost::intrusive_ptr<Y> p( new Y );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> p2( std::move( p ) );
BOOST_TEST( N::base::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( N::base::instances == 0 );
}
{
boost::intrusive_ptr<X> p( new X );
BOOST_TEST( N::base::instances == 1 );
@ -170,6 +182,33 @@ int main()
BOOST_TEST( N::base::instances == 0 );
}
{
boost::intrusive_ptr<Y> p( new Y );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> p2;
p2 = std::move( p );
BOOST_TEST( N::base::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( N::base::instances == 0 );
}
{
boost::intrusive_ptr<Y> p( new Y );
BOOST_TEST( N::base::instances == 1 );
boost::intrusive_ptr<X> p2( new X );
BOOST_TEST( N::base::instances == 2 );
p2 = std::move( p );
BOOST_TEST( N::base::instances == 1 );
BOOST_TEST( p.get() == 0 );
p2.reset();
BOOST_TEST( N::base::instances == 0 );
}
return boost::report_errors();
}

View File

@ -0,0 +1,255 @@
#include <boost/config.hpp>
// shared_ptr_alias_move_test.cpp
//
// Copyright (c) 2007 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/detail/lightweight_test.hpp>
#include <boost/shared_ptr.hpp>
#include <utility>
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
class incomplete;
struct X
{
static long instances;
int v_;
explicit X( int v ): v_( v )
{
++instances;
}
~X()
{
v_ = 0;
--instances;
}
private:
X( X const & );
X & operator=( X const & );
};
long X::instances = 0;
int main()
{
BOOST_TEST( X::instances == 0 );
{
int m = 0;
boost::shared_ptr< int > p;
boost::shared_ptr< int > p2( std::move( p ), &m );
BOOST_TEST( p2.get() == &m );
BOOST_TEST( p2? true: false );
BOOST_TEST( !!p2 );
BOOST_TEST( p2.use_count() == 0 );
BOOST_TEST( p.get() == 0 );
BOOST_TEST( p.use_count() == 0 );
p2.reset( std::move( p ), 0 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p2? false: true );
BOOST_TEST( !p2 );
BOOST_TEST( p2.use_count() == 0 );
BOOST_TEST( p.get() == 0 );
BOOST_TEST( p.use_count() == 0 );
}
{
int m = 0;
boost::shared_ptr< int > p( new int );
boost::shared_ptr< int const > p2( std::move( p ), &m );
BOOST_TEST( p2.get() == &m );
BOOST_TEST( p2? true: false );
BOOST_TEST( !!p2 );
BOOST_TEST( p2.use_count() == 1 );
BOOST_TEST( p.get() == 0 );
BOOST_TEST( p.use_count() == 0 );
boost::shared_ptr< int volatile > p3;
p2.reset( std::move( p3 ), 0 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p2? false: true );
BOOST_TEST( !p2 );
BOOST_TEST( p2.use_count() == 0 );
BOOST_TEST( p3.get() == 0 );
BOOST_TEST( p3.use_count() == 0 );
boost::shared_ptr< int const volatile > p4( new int );
p2.reset( std::move( p4 ), &m );
BOOST_TEST( p2.get() == &m );
BOOST_TEST( p2.use_count() == 1 );
BOOST_TEST( p4.get() == 0 );
BOOST_TEST( p4.use_count() == 0 );
}
{
boost::shared_ptr< int > p( new int );
boost::shared_ptr< void const > p2( std::move( p ), 0 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p2? false: true );
BOOST_TEST( !p2 );
BOOST_TEST( p2.use_count() == 1 );
BOOST_TEST( p.get() == 0 );
BOOST_TEST( p.use_count() == 0 );
int m = 0;
boost::shared_ptr< void volatile > p3;
p2.reset( std::move( p3 ), &m );
BOOST_TEST( p2.get() == &m );
BOOST_TEST( p2? true: false );
BOOST_TEST( !!p2 );
BOOST_TEST( p2.use_count() == 0 );
BOOST_TEST( p3.get() == 0 );
BOOST_TEST( p3.use_count() == 0 );
boost::shared_ptr< void const volatile > p4( new int );
p2.reset( std::move( p4 ), 0 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p2.use_count() == 1 );
BOOST_TEST( p4.get() == 0 );
BOOST_TEST( p4.use_count() == 0 );
}
{
boost::shared_ptr< incomplete > p;
boost::shared_ptr< incomplete > p2( std::move( p ), 0 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p2? false: true );
BOOST_TEST( !p2 );
BOOST_TEST( p2.use_count() == 0 );
BOOST_TEST( p.get() == 0 );
BOOST_TEST( p.use_count() == 0 );
p2.reset( std::move( p ), 0 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p2? false: true );
BOOST_TEST( !p2 );
BOOST_TEST( p2.use_count() == 0 );
BOOST_TEST( p.get() == 0 );
BOOST_TEST( p.use_count() == 0 );
}
{
boost::shared_ptr< X > p( new X( 5 ) ), q( p );
boost::shared_ptr< int const > p2( std::move( q ), &q->v_ );
BOOST_TEST( p2.get() == &p->v_ );
BOOST_TEST( p2? true: false );
BOOST_TEST( !!p2 );
BOOST_TEST( p2.use_count() == p.use_count() );
BOOST_TEST( !( p < p2 ) && !( p2 < p ) );
BOOST_TEST( q.get() == 0 );
BOOST_TEST( q.use_count() == 0 );
p.reset();
BOOST_TEST( *p2 == 5 );
boost::shared_ptr< X const > p3( new X( 8 ) ), q3( p3 );
p2.reset( std::move( q3 ), &q3->v_ );
BOOST_TEST( p2.get() == &p3->v_ );
BOOST_TEST( p2? true: false );
BOOST_TEST( !!p2 );
BOOST_TEST( p2.use_count() == p3.use_count() );
BOOST_TEST( !( p3 < p2 ) && !( p2 < p3 ) );
BOOST_TEST( q3.get() == 0 );
BOOST_TEST( q3.use_count() == 0 );
p3.reset();
BOOST_TEST( *p2 == 8 );
}
{
boost::shared_ptr< X > p( new X( 5 ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.unique() );
BOOST_TEST( p->v_ == 5 );
boost::shared_ptr< X > p2( std::move( p ), p.get() );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == 0 );
BOOST_TEST( p2.unique() );
BOOST_TEST( p2->v_ == 5 );
boost::shared_ptr< int const > p3( std::move( p2 ), &p2->v_ );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p3.unique() );
BOOST_TEST( *p3 == 5 );
p3.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X > p( new X( 5 ) );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.unique() );
BOOST_TEST( p->v_ == 5 );
{
boost::shared_ptr< X > p2(p);
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.get() == p2.get() );
BOOST_TEST( p.use_count() == 2 );
BOOST_TEST( p2.use_count() == 2 );
boost::shared_ptr< int const > p3( std::move( p2 ), &p2->v_ );
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.use_count() == 2 );
BOOST_TEST( p2.use_count() == 0 );
BOOST_TEST( p2.get() == 0 );
BOOST_TEST( p3.use_count() == 2 );
BOOST_TEST( p3.get() == &p->v_ );
}
BOOST_TEST( X::instances == 1 );
BOOST_TEST( p.unique() );
BOOST_TEST( p->v_ == 5 );
}
return boost::report_errors();
}
#else // defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
int main()
{
return 0;
}
#endif