From a7fbb0a8415acae2a8507d697653930e31f19dd6 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 6 Nov 2016 15:35:46 +0200 Subject: [PATCH] Do not use components removed in C++17 (auto_ptr, binary_function) --- include/boost/smart_ptr/owner_less.hpp | 45 +++++++------------------- test/auto_ptr_rv_test.cpp | 12 +++++++ test/esft_regtest.cpp | 5 +++ test/pointer_to_other_test.cpp | 7 ++++ test/shared_from_raw_test2.cpp | 5 +++ test/shared_ptr_test.cpp | 8 +++++ 6 files changed, 48 insertions(+), 34 deletions(-) diff --git a/include/boost/smart_ptr/owner_less.hpp b/include/boost/smart_ptr/owner_less.hpp index 6899325..75d182c 100644 --- a/include/boost/smart_ptr/owner_less.hpp +++ b/include/boost/smart_ptr/owner_less.hpp @@ -5,6 +5,7 @@ // owner_less.hpp // // Copyright (c) 2008 Frank Mori Hess +// Copyright (c) 2016 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. (See // 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. // -#include - namespace boost { - template class shared_ptr; - template class weak_ptr; - namespace detail - { - template - struct generic_owner_less : public std::binary_function +template struct owner_less +{ + typedef bool result_type; + typedef T first_argument_type; + typedef T second_argument_type; + + template bool operator()( U const & u, V const & v ) const { - bool operator()(const T &lhs, const T &rhs) const - { - 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 struct owner_less; - - template - struct owner_less >: - public detail::generic_owner_less, weak_ptr > - {}; - - template - struct owner_less >: - public detail::generic_owner_less, shared_ptr > - {}; + return u.owner_before( v ); + } +}; } // namespace boost diff --git a/test/auto_ptr_rv_test.cpp b/test/auto_ptr_rv_test.cpp index d13b6ab..5123439 100644 --- a/test/auto_ptr_rv_test.cpp +++ b/test/auto_ptr_rv_test.cpp @@ -1,3 +1,5 @@ +#include + // // auto_ptr_rv_test.cpp // @@ -8,6 +10,14 @@ // http://www.boost.org/LICENSE_1_0.txt // +#if defined( BOOST_NO_AUTO_PTR ) + +int main() +{ +} + +#else + #include #include #include @@ -109,3 +119,5 @@ int main() return boost::report_errors(); } + +#endif // #if defined( BOOST_NO_AUTO_PTR ) diff --git a/test/esft_regtest.cpp b/test/esft_regtest.cpp index cc180a2..baa5ef2 100644 --- a/test/esft_regtest.cpp +++ b/test/esft_regtest.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -77,11 +78,15 @@ void test() BOOST_TEST( X::instances == 0 ); +#if !defined( BOOST_NO_AUTO_PTR ) + { std::auto_ptr px( new X( 0 ) ); BOOST_TEST( X::instances == 1 ); } +#endif + BOOST_TEST( X::instances == 0 ); { diff --git a/test/pointer_to_other_test.cpp b/test/pointer_to_other_test.cpp index c2ee187..f1c6091 100644 --- a/test/pointer_to_other_test.cpp +++ b/test/pointer_to_other_test.cpp @@ -16,8 +16,11 @@ #include #include +#include + #include + template void assert_same_type( T** pt = 0, U** pu = 0 ) { pt = pu; @@ -58,12 +61,16 @@ int main() assert_same_type< boost::pointer_to_other< boost::intrusive_ptr, void >::type, boost::intrusive_ptr >(); assert_same_type< boost::pointer_to_other< boost::intrusive_ptr, Y >::type, boost::intrusive_ptr >(); +#if !defined( BOOST_NO_AUTO_PTR ) + // auto_ptr assert_same_type< boost::pointer_to_other< std::auto_ptr, Y >::type, std::auto_ptr >(); assert_same_type< boost::pointer_to_other< std::auto_ptr, void >::type, std::auto_ptr >(); assert_same_type< boost::pointer_to_other< std::auto_ptr, Y >::type, std::auto_ptr >(); +#endif + // raw pointer assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >(); diff --git a/test/shared_from_raw_test2.cpp b/test/shared_from_raw_test2.cpp index 8148a6b..2a33637 100644 --- a/test/shared_from_raw_test2.cpp +++ b/test/shared_from_raw_test2.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -75,11 +76,15 @@ void test() BOOST_TEST( X::instances == 0 ); +#if !defined( BOOST_NO_AUTO_PTR ) + { std::auto_ptr px( new X( 0 ) ); BOOST_TEST( X::instances == 1 ); } +#endif + BOOST_TEST( X::instances == 0 ); { diff --git a/test/shared_ptr_test.cpp b/test/shared_ptr_test.cpp index 60ed906..fdfb215 100644 --- a/test/shared_ptr_test.cpp +++ b/test/shared_ptr_test.cpp @@ -850,6 +850,8 @@ void weak_ptr_constructor() void auto_ptr_constructor() { +#if !defined( BOOST_NO_AUTO_PTR ) + { std::auto_ptr p; boost::shared_ptr pi(p); @@ -1136,6 +1138,8 @@ void auto_ptr_constructor() BOOST_TEST(X::instances == 0); BOOST_TEST(Y::instances == 0); + +#endif // #if !defined( BOOST_NO_AUTO_PTR ) } void test() @@ -1420,6 +1424,8 @@ void conversion_assignment() void auto_ptr_assignment() { +#if !defined( BOOST_NO_AUTO_PTR ) + { boost::shared_ptr p1; @@ -1516,6 +1522,8 @@ void auto_ptr_assignment() BOOST_TEST(X::instances == 0); BOOST_TEST(Y::instances == 0); } + +#endif // #if !defined( BOOST_NO_AUTO_PTR ) } void test()