Do not use components removed in C++17 (auto_ptr, binary_function)

This commit is contained in:
Peter Dimov
2016-11-06 15:35:46 +02:00
parent bdc19dee01
commit a7fbb0a841
6 changed files with 48 additions and 34 deletions

View File

@ -5,6 +5,7 @@
// owner_less.hpp // owner_less.hpp
// //
// Copyright (c) 2008 Frank Mori Hess // Copyright (c) 2008 Frank Mori Hess
// Copyright (c) 2016 Peter Dimov
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at
@ -13,44 +14,20 @@
// See http://www.boost.org/libs/smart_ptr/smart_ptr.htm for documentation. // See http://www.boost.org/libs/smart_ptr/smart_ptr.htm for documentation.
// //
#include <functional>
namespace boost namespace boost
{ {
template<typename T> class shared_ptr;
template<typename T> class weak_ptr;
namespace detail template<class T = void> struct owner_less
{ {
template<typename T, typename U> typedef bool result_type;
struct generic_owner_less : public std::binary_function<T, T, bool> typedef T first_argument_type;
typedef T second_argument_type;
template<class U, class V> bool operator()( U const & u, V const & v ) const
{ {
bool operator()(const T &lhs, const T &rhs) const return u.owner_before( v );
{ }
return lhs.owner_before(rhs); };
}
bool operator()(const T &lhs, const U &rhs) const
{
return lhs.owner_before(rhs);
}
bool operator()(const U &lhs, const T &rhs) const
{
return lhs.owner_before(rhs);
}
};
} // namespace detail
template<typename T> struct owner_less;
template<typename T>
struct owner_less<shared_ptr<T> >:
public detail::generic_owner_less<shared_ptr<T>, weak_ptr<T> >
{};
template<typename T>
struct owner_less<weak_ptr<T> >:
public detail::generic_owner_less<weak_ptr<T>, shared_ptr<T> >
{};
} // namespace boost } // namespace boost

View File

@ -1,3 +1,5 @@
#include <boost/config.hpp>
// //
// auto_ptr_rv_test.cpp // auto_ptr_rv_test.cpp
// //
@ -8,6 +10,14 @@
// http://www.boost.org/LICENSE_1_0.txt // http://www.boost.org/LICENSE_1_0.txt
// //
#if defined( BOOST_NO_AUTO_PTR )
int main()
{
}
#else
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
#include <memory> #include <memory>
@ -109,3 +119,5 @@ int main()
return boost::report_errors(); return boost::report_errors();
} }
#endif // #if defined( BOOST_NO_AUTO_PTR )

View File

@ -15,6 +15,7 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
#include <boost/config.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
@ -77,11 +78,15 @@ void test()
BOOST_TEST( X::instances == 0 ); BOOST_TEST( X::instances == 0 );
#if !defined( BOOST_NO_AUTO_PTR )
{ {
std::auto_ptr<X> px( new X( 0 ) ); std::auto_ptr<X> px( new X( 0 ) );
BOOST_TEST( X::instances == 1 ); BOOST_TEST( X::instances == 1 );
} }
#endif
BOOST_TEST( X::instances == 0 ); BOOST_TEST( X::instances == 0 );
{ {

View File

@ -16,8 +16,11 @@
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <boost/intrusive_ptr.hpp> #include <boost/intrusive_ptr.hpp>
#include <boost/config.hpp>
#include <memory> #include <memory>
template<class T, class U> void assert_same_type( T** pt = 0, U** pu = 0 ) template<class T, class U> void assert_same_type( T** pt = 0, U** pu = 0 )
{ {
pt = pu; pt = pu;
@ -58,12 +61,16 @@ int main()
assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, void >::type, boost::intrusive_ptr<void> >(); assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, void >::type, boost::intrusive_ptr<void> >();
assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<void>, Y >::type, boost::intrusive_ptr<Y> >(); assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<void>, Y >::type, boost::intrusive_ptr<Y> >();
#if !defined( BOOST_NO_AUTO_PTR )
// auto_ptr // auto_ptr
assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, Y >::type, std::auto_ptr<Y> >(); assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, Y >::type, std::auto_ptr<Y> >();
assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, void >::type, std::auto_ptr<void> >(); assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, void >::type, std::auto_ptr<void> >();
assert_same_type< boost::pointer_to_other< std::auto_ptr<void>, Y >::type, std::auto_ptr<Y> >(); assert_same_type< boost::pointer_to_other< std::auto_ptr<void>, Y >::type, std::auto_ptr<Y> >();
#endif
// raw pointer // raw pointer
assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >(); assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >();

View File

@ -13,6 +13,7 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
#include <boost/config.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
@ -75,11 +76,15 @@ void test()
BOOST_TEST( X::instances == 0 ); BOOST_TEST( X::instances == 0 );
#if !defined( BOOST_NO_AUTO_PTR )
{ {
std::auto_ptr<X> px( new X( 0 ) ); std::auto_ptr<X> px( new X( 0 ) );
BOOST_TEST( X::instances == 1 ); BOOST_TEST( X::instances == 1 );
} }
#endif
BOOST_TEST( X::instances == 0 ); BOOST_TEST( X::instances == 0 );
{ {

View File

@ -850,6 +850,8 @@ void weak_ptr_constructor()
void auto_ptr_constructor() void auto_ptr_constructor()
{ {
#if !defined( BOOST_NO_AUTO_PTR )
{ {
std::auto_ptr<int> p; std::auto_ptr<int> p;
boost::shared_ptr<int> pi(p); boost::shared_ptr<int> pi(p);
@ -1136,6 +1138,8 @@ void auto_ptr_constructor()
BOOST_TEST(X::instances == 0); BOOST_TEST(X::instances == 0);
BOOST_TEST(Y::instances == 0); BOOST_TEST(Y::instances == 0);
#endif // #if !defined( BOOST_NO_AUTO_PTR )
} }
void test() void test()
@ -1420,6 +1424,8 @@ void conversion_assignment()
void auto_ptr_assignment() void auto_ptr_assignment()
{ {
#if !defined( BOOST_NO_AUTO_PTR )
{ {
boost::shared_ptr<int> p1; boost::shared_ptr<int> p1;
@ -1516,6 +1522,8 @@ void auto_ptr_assignment()
BOOST_TEST(X::instances == 0); BOOST_TEST(X::instances == 0);
BOOST_TEST(Y::instances == 0); BOOST_TEST(Y::instances == 0);
} }
#endif // #if !defined( BOOST_NO_AUTO_PTR )
} }
void test() void test()