forked from boostorg/smart_ptr
Make shared_from_this and weak_from_this private in enable_shared_from. Fixes #75.
This commit is contained in:
@ -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
|
||||||
|
@ -356,3 +356,6 @@ run allocate_unique_value_test.cpp ;
|
|||||||
run sp_guides_test.cpp ;
|
run sp_guides_test.cpp ;
|
||||||
run sp_guides_test2.cpp ;
|
run sp_guides_test2.cpp ;
|
||||||
run wp_guides_test.cpp ;
|
run wp_guides_test.cpp ;
|
||||||
|
|
||||||
|
compile-fail shared_from_fail.cpp ;
|
||||||
|
compile-fail weak_from_fail.cpp ;
|
||||||
|
16
test/shared_from_fail.cpp
Normal file
16
test/shared_from_fail.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px( new X );
|
||||||
|
px->shared_from_this();
|
||||||
|
}
|
16
test/weak_from_fail.cpp
Normal file
16
test/weak_from_fail.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<X> px( new X );
|
||||||
|
px->weak_from_this();
|
||||||
|
}
|
Reference in New Issue
Block a user