mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-08-03 14:44:26 +02:00
Add deduction guides to shared_ptr and weak_ptr. Fixes #73.
This commit is contained in:
@@ -1175,6 +1175,13 @@ template<class D, class T> D const * basic_get_local_deleter( D const *, shared_
|
||||
|
||||
} // 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
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
#if defined(__cpp_deduction_guides)
|
||||
|
||||
template<class T> weak_ptr( shared_ptr<T> ) -> weak_ptr<T>;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED
|
||||
|
@@ -352,3 +352,7 @@ run allocate_unique_noinit_test.cpp ;
|
||||
run allocate_unique_test.cpp ;
|
||||
run allocate_unique_throws_test.cpp ;
|
||||
run allocate_unique_value_test.cpp ;
|
||||
|
||||
run sp_guides_test.cpp ;
|
||||
run sp_guides_test2.cpp ;
|
||||
run wp_guides_test.cpp ;
|
||||
|
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
|
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