mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-11-20 17:29:48 +01:00
Use explicit operator bool when available; add nullptr support to shared_ptr. Refs #4116.
[SVN r81780]
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
// This header intentionally has no include guards.
|
||||
//
|
||||
// Copyright (c) 2001-2009 Peter Dimov
|
||||
// Copyright (c) 2001-2009, 2012 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
|
||||
|
||||
#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
|
||||
#if !defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) && !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
explicit operator bool () const BOOST_NOEXCEPT
|
||||
{
|
||||
return px != 0;
|
||||
}
|
||||
|
||||
#elif ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
|
||||
|
||||
operator bool () const BOOST_NOEXCEPT
|
||||
{
|
||||
|
||||
@@ -218,6 +218,30 @@ template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_p
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
template<class T> inline bool operator==( intrusive_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator==( std::nullptr_t, intrusive_ptr<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( intrusive_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( std::nullptr_t, intrusive_ptr<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
|
||||
{
|
||||
return std::less<T *>()(a.get(), b.get());
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// http://www.boost.org/libs/smart_ptr/scoped_array.htm
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/checked_delete.hpp>
|
||||
#include <boost/config.hpp> // in case ptrdiff_t not in std
|
||||
@@ -97,6 +98,30 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
template<class T> inline bool operator==( scoped_array<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator==( std::nullptr_t, scoped_array<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( scoped_array<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( std::nullptr_t, scoped_array<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) BOOST_NOEXCEPT
|
||||
{
|
||||
a.swap(b);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// http://www.boost.org/libs/smart_ptr/scoped_ptr.htm
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/checked_delete.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
@@ -114,6 +115,30 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
template<class T> inline bool operator==( scoped_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator==( std::nullptr_t, scoped_ptr<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( scoped_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( std::nullptr_t, scoped_ptr<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) BOOST_NOEXCEPT
|
||||
{
|
||||
a.swap(b);
|
||||
|
||||
@@ -243,6 +243,30 @@ template<class T> inline bool operator!=(shared_array<T> const & a, shared_array
|
||||
return a.get() != b.get();
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
template<class T> inline bool operator==( shared_array<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator==( std::nullptr_t, shared_array<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( shared_array<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( std::nullptr_t, shared_array<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class T> inline bool operator<(shared_array<T> const & a, shared_array<T> const & b) BOOST_NOEXCEPT
|
||||
{
|
||||
return std::less<T*>()(a.get(), b.get());
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#include <algorithm> // for std::swap
|
||||
#include <functional> // for std::less
|
||||
#include <typeinfo> // for std::bad_cast
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <cstddef> // for std::size_t, std::nullptr_t
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM)
|
||||
#if !defined(BOOST_NO_IOSFWD)
|
||||
@@ -339,6 +339,14 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
shared_ptr( std::nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() // never throws
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class Y>
|
||||
explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete
|
||||
{
|
||||
@@ -356,6 +364,14 @@ public:
|
||||
boost::detail::sp_deleter_construct( this, p );
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
template<class D> shared_ptr( std::nullptr_t p, D d ): px( p ), pn( p, d )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// As above, but with allocator. A's copy constructor shall not throw.
|
||||
|
||||
template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
|
||||
@@ -363,6 +379,14 @@ public:
|
||||
boost::detail::sp_deleter_construct( this, p );
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
template<class D, class A> shared_ptr( std::nullptr_t p, D d, A a ): px( p ), pn( p, d, a )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// generated copy constructor, destructor are fine...
|
||||
|
||||
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||
@@ -577,6 +601,16 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
shared_ptr & operator=( std::nullptr_t ) BOOST_NOEXCEPT // never throws
|
||||
{
|
||||
this_type().swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void reset() BOOST_NOEXCEPT // never throws in 1.30+
|
||||
@@ -711,6 +745,30 @@ template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T>
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
template<class T> inline bool operator==( shared_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator==( std::nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() == 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( shared_ptr<T> const & p, std::nullptr_t ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
template<class T> inline bool operator!=( std::nullptr_t, shared_ptr<T> const & p ) BOOST_NOEXCEPT
|
||||
{
|
||||
return p.get() != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b) BOOST_NOEXCEPT
|
||||
{
|
||||
return a.owner_before( b );
|
||||
|
||||
Reference in New Issue
Block a user