forked from boostorg/smart_ptr
Merge branch 'develop' of https://github.com/boostorg/smart_ptr into cppbuilder
This commit is contained in:
@@ -21,11 +21,12 @@ public:
|
|||||||
count_ = shared_count(base);
|
count_ = shared_count(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT {
|
void local_cb_destroy() BOOST_SP_NOEXCEPT BOOST_OVERRIDE {
|
||||||
shared_count().swap(count_);
|
shared_count().swap(count_);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT {
|
shared_count local_cb_get_shared_count() const
|
||||||
|
BOOST_SP_NOEXCEPT BOOST_OVERRIDE {
|
||||||
return count_;
|
return count_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -206,28 +206,29 @@ public:
|
|||||||
return state_;
|
return state_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() BOOST_SP_NOEXCEPT {
|
void dispose() BOOST_SP_NOEXCEPT BOOST_OVERRIDE {
|
||||||
boost::alloc_destroy_n(state_.allocator(),
|
boost::alloc_destroy_n(state_.allocator(),
|
||||||
boost::first_scalar(sp_array_start<type>(this)),
|
boost::first_scalar(sp_array_start<type>(this)),
|
||||||
state_.size() * sp_array_count<type>::value);
|
state_.size() * sp_array_count<type>::value);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void destroy() BOOST_SP_NOEXCEPT {
|
void destroy() BOOST_SP_NOEXCEPT BOOST_OVERRIDE {
|
||||||
sp_array_creator<allocator, sp_array_base> other(state_.allocator(),
|
sp_array_creator<allocator, sp_array_base> other(state_.allocator(),
|
||||||
state_.size());
|
state_.size());
|
||||||
this->~sp_array_base();
|
this->~sp_array_base();
|
||||||
other.destroy(this);
|
other.destroy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* get_deleter(const sp_typeinfo_&) BOOST_SP_NOEXCEPT {
|
void* get_deleter(const sp_typeinfo_&) BOOST_SP_NOEXCEPT BOOST_OVERRIDE {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* get_local_deleter(const sp_typeinfo_&) BOOST_SP_NOEXCEPT {
|
void* get_local_deleter(const sp_typeinfo_&)
|
||||||
|
BOOST_SP_NOEXCEPT BOOST_OVERRIDE {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* get_untyped_deleter() BOOST_SP_NOEXCEPT {
|
void* get_untyped_deleter() BOOST_SP_NOEXCEPT BOOST_OVERRIDE {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@ class bad_weak_ptr: public std::exception
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual char const * what() const BOOST_NOEXCEPT_OR_NOTHROW
|
virtual char const * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return "tr1::bad_weak_ptr";
|
return "tr1::bad_weak_ptr";
|
||||||
}
|
}
|
||||||
|
@@ -113,12 +113,12 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT
|
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT
|
virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return pn_;
|
return pn_;
|
||||||
}
|
}
|
||||||
@@ -130,12 +130,12 @@ public:
|
|||||||
|
|
||||||
shared_count pn_;
|
shared_count pn_;
|
||||||
|
|
||||||
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT
|
virtual void local_cb_destroy() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
shared_count().swap( pn_ );
|
shared_count().swap( pn_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT
|
virtual boost::detail::shared_count local_cb_get_shared_count() const BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return pn_;
|
return pn_;
|
||||||
}
|
}
|
||||||
|
@@ -85,7 +85,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() BOOST_SP_NOEXCEPT
|
virtual void dispose() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
|
||||||
boost::sp_scalar_destructor_hook( px_, sizeof(X), this );
|
boost::sp_scalar_destructor_hook( px_, sizeof(X), this );
|
||||||
@@ -93,17 +93,17 @@ public:
|
|||||||
boost::checked_delete( px_ );
|
boost::checked_delete( px_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_deleter( sp_typeinfo_ const & ) BOOST_SP_NOEXCEPT
|
virtual void * get_deleter( sp_typeinfo_ const & ) BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_local_deleter( sp_typeinfo_ const & ) BOOST_SP_NOEXCEPT
|
virtual void * get_local_deleter( sp_typeinfo_ const & ) BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT
|
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -168,22 +168,22 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() BOOST_SP_NOEXCEPT
|
virtual void dispose() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
del( ptr );
|
del( ptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
|
virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return ti == BOOST_SP_TYPEID_(D)? &reinterpret_cast<char&>( del ): 0;
|
return ti == BOOST_SP_TYPEID_(D)? &reinterpret_cast<char&>( del ): 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT
|
virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return ti == BOOST_SP_TYPEID_(D)? boost::detail::get_local_deleter( boost::addressof( del ) ): 0;
|
return ti == BOOST_SP_TYPEID_(D)? boost::detail::get_local_deleter( boost::addressof( del ) ): 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT
|
virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
return &reinterpret_cast<char&>( del );
|
return &reinterpret_cast<char&>( del );
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// enable_shared_from.hpp
|
// enable_shared_from.hpp
|
||||||
//
|
//
|
||||||
// Copyright 2019 Peter Dimov
|
// Copyright 2019, 2020 Peter Dimov
|
||||||
//
|
//
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@@ -19,17 +19,21 @@ namespace boost
|
|||||||
|
|
||||||
class enable_shared_from: public enable_shared_from_this<enable_shared_from>
|
class enable_shared_from: public enable_shared_from_this<enable_shared_from>
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
using enable_shared_from_this<enable_shared_from>::shared_from_this;
|
||||||
|
using enable_shared_from_this<enable_shared_from>::weak_from_this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<class T> shared_ptr<T> shared_from( T * p )
|
template<class T> shared_ptr<T> shared_from( T * p )
|
||||||
{
|
{
|
||||||
return shared_ptr<T>( p->enable_shared_from::shared_from_this(), p );
|
return shared_ptr<T>( p->enable_shared_from_this<enable_shared_from>::shared_from_this(), p );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T> weak_ptr<T> weak_from( T * p ) BOOST_SP_NOEXCEPT
|
template<class T> weak_ptr<T> weak_from( T * p ) BOOST_SP_NOEXCEPT
|
||||||
{
|
{
|
||||||
return weak_ptr<T>( p->enable_shared_from::weak_from_this(), p );
|
return weak_ptr<T>( p->enable_shared_from_this<enable_shared_from>::weak_from_this(), p );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@@ -1175,6 +1175,13 @@ template<class D, class T> D const * basic_get_local_deleter( D const *, shared_
|
|||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
#if defined(__cpp_deduction_guides)
|
||||||
|
|
||||||
|
template<class T> shared_ptr( weak_ptr<T> ) -> shared_ptr<T>;
|
||||||
|
template<class T, class D> shared_ptr( std::unique_ptr<T, D> ) -> shared_ptr<T>;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
#if defined( BOOST_SP_DISABLE_DEPRECATED )
|
||||||
|
@@ -264,6 +264,12 @@ template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b) BOOST_SP_NOEXCEPT
|
|||||||
a.swap(b);
|
a.swap(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__cpp_deduction_guides)
|
||||||
|
|
||||||
|
template<class T> weak_ptr( shared_ptr<T> ) -> weak_ptr<T>;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // #ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED
|
#endif // #ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED
|
||||||
|
@@ -352,3 +352,12 @@ run allocate_unique_noinit_test.cpp ;
|
|||||||
run allocate_unique_test.cpp ;
|
run allocate_unique_test.cpp ;
|
||||||
run allocate_unique_throws_test.cpp ;
|
run allocate_unique_throws_test.cpp ;
|
||||||
run allocate_unique_value_test.cpp ;
|
run allocate_unique_value_test.cpp ;
|
||||||
|
|
||||||
|
run sp_guides_test.cpp ;
|
||||||
|
run sp_guides_test2.cpp ;
|
||||||
|
run wp_guides_test.cpp ;
|
||||||
|
|
||||||
|
compile-fail shared_from_fail.cpp ;
|
||||||
|
compile-fail weak_from_fail.cpp ;
|
||||||
|
|
||||||
|
compile sp_override_test.cpp ;
|
||||||
|
22
test/shared_from_fail.cpp
Normal file
22
test/shared_from_fail.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2020 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/smart_ptr/enable_shared_from.hpp>
|
||||||
|
|
||||||
|
struct X: public boost::enable_shared_from
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(__clang__) && defined(_MSC_VER)
|
||||||
|
// clang-cl claims that it accepts this code for compatibility
|
||||||
|
// with msvc, but no version of msvc accepts it
|
||||||
|
# pragma clang diagnostic error "-Wmicrosoft-using-decl"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px( new X );
|
||||||
|
px->shared_from_this();
|
||||||
|
}
|
25
test/sp_guides_test.cpp
Normal file
25
test/sp_guides_test.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#if defined(__cpp_deduction_guides)
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<int> p1( new int );
|
||||||
|
boost::weak_ptr<int> p2( p1 );
|
||||||
|
boost::shared_ptr p3( p2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/config/pragma_message.hpp>
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE( "Skipping test because __cpp_deduction_guides is not defined" )
|
||||||
|
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#endif
|
23
test/sp_guides_test2.cpp
Normal file
23
test/sp_guides_test2.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#if defined(__cpp_deduction_guides)
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr p2( std::unique_ptr<int>( new int ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/config/pragma_message.hpp>
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE( "Skipping test because __cpp_deduction_guides is not defined" )
|
||||||
|
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#endif
|
18
test/sp_override_test.cpp
Normal file
18
test/sp_override_test.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && __GNUC__ >= 5 && __cplusplus >= 201103L
|
||||||
|
# pragma GCC diagnostic error "-Wsuggest-override"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/smart_ptr.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<int> p1( new int );
|
||||||
|
boost::shared_ptr<int[]> p2( new int[1] );
|
||||||
|
|
||||||
|
boost::make_shared<int>();
|
||||||
|
boost::make_shared<int[]>( 1 );
|
||||||
|
}
|
22
test/weak_from_fail.cpp
Normal file
22
test/weak_from_fail.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2020 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/smart_ptr/enable_shared_from.hpp>
|
||||||
|
|
||||||
|
struct X: public boost::enable_shared_from
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(__clang__) && defined(_MSC_VER)
|
||||||
|
// clang-cl claims that it accepts this code for compatibility
|
||||||
|
// with msvc, but no version of msvc accepts it
|
||||||
|
# pragma clang diagnostic error "-Wmicrosoft-using-decl"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px( new X );
|
||||||
|
px->weak_from_this();
|
||||||
|
}
|
24
test/wp_guides_test.cpp
Normal file
24
test/wp_guides_test.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#if defined(__cpp_deduction_guides)
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/weak_ptr.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<int> p1( new int );
|
||||||
|
boost::weak_ptr p2( p1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <boost/config/pragma_message.hpp>
|
||||||
|
|
||||||
|
BOOST_PRAGMA_MESSAGE( "Skipping test because __cpp_deduction_guides is not defined" )
|
||||||
|
|
||||||
|
int main() {}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user