Do not require boost::hash in the std::hash specializations

This commit is contained in:
Peter Dimov
2020-06-03 17:38:03 +03:00
parent 688cfed63e
commit bc677e9098
6 changed files with 20 additions and 44 deletions

View File

@@ -394,9 +394,9 @@ namespace std
template<class T> struct hash< ::boost::intrusive_ptr<T> > template<class T> struct hash< ::boost::intrusive_ptr<T> >
{ {
std::size_t operator()( ::boost::intrusive_ptr<T> const & v ) const BOOST_SP_NOEXCEPT std::size_t operator()( ::boost::intrusive_ptr<T> const & p ) const BOOST_SP_NOEXCEPT
{ {
return hash_value( v ); return std::hash< T* >()( p.get() );
} }
}; };

View File

@@ -697,9 +697,9 @@ namespace std
template<class T> struct hash< ::boost::local_shared_ptr<T> > template<class T> struct hash< ::boost::local_shared_ptr<T> >
{ {
std::size_t operator()( ::boost::local_shared_ptr<T> const & v ) const BOOST_SP_NOEXCEPT std::size_t operator()( ::boost::local_shared_ptr<T> const & p ) const BOOST_SP_NOEXCEPT
{ {
return hash_value( v ); return std::hash< typename ::boost::local_shared_ptr<T>::element_type* >()( p.get() );
} }
}; };

View File

@@ -1174,9 +1174,9 @@ namespace std
template<class T> struct hash< ::boost::shared_ptr<T> > template<class T> struct hash< ::boost::shared_ptr<T> >
{ {
std::size_t operator()( ::boost::shared_ptr<T> const & v ) const BOOST_SP_NOEXCEPT std::size_t operator()( ::boost::shared_ptr<T> const & p ) const BOOST_SP_NOEXCEPT
{ {
return hash_value( v ); return std::hash< typename ::boost::shared_ptr<T>::element_type* >()( p.get() );
} }
}; };

View File

@@ -3,7 +3,6 @@
// https://www.boost.org/LICENSE_1_0.txt // https://www.boost.org/LICENSE_1_0.txt
#include <boost/intrusive_ptr.hpp> #include <boost/intrusive_ptr.hpp>
#include <boost/functional/hash.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <functional> #include <functional>
@@ -57,13 +56,10 @@ struct X: public base
int main() int main()
{ {
boost::hash< boost::intrusive_ptr<X> > hasher;
std::hash< boost::intrusive_ptr<X> > hasher2;
boost::intrusive_ptr<X> p1, p2( new X ); boost::intrusive_ptr<X> p1, p2( new X );
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) ); BOOST_TEST_EQ( std::hash< boost::intrusive_ptr<X> >()( p1 ), std::hash< X* >()( p1.get() ) );
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) ); BOOST_TEST_EQ( std::hash< boost::intrusive_ptr<X> >()( p2 ), std::hash< X* >()( p2.get() ) );
return boost::report_errors(); return boost::report_errors();
} }

View File

@@ -3,7 +3,6 @@
// https://www.boost.org/LICENSE_1_0.txt // https://www.boost.org/LICENSE_1_0.txt
#include <boost/smart_ptr/local_shared_ptr.hpp> #include <boost/smart_ptr/local_shared_ptr.hpp>
#include <boost/functional/hash.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <functional> #include <functional>
@@ -17,33 +16,24 @@ int main() {}
int main() int main()
{ {
{ {
boost::hash< boost::local_shared_ptr<int> > hasher;
std::hash< boost::local_shared_ptr<int> > hasher2;
boost::local_shared_ptr<int> p1, p2( new int ); boost::local_shared_ptr<int> p1, p2( new int );
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) ); BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int> >()( p1 ), std::hash< int* >()( p1.get() ) );
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) ); BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int> >()( p2 ), std::hash< int* >()( p2.get() ) );
} }
{ {
boost::hash< boost::local_shared_ptr<int[]> > hasher;
std::hash< boost::local_shared_ptr<int[]> > hasher2;
boost::local_shared_ptr<int[]> p1, p2( new int[1] ); boost::local_shared_ptr<int[]> p1, p2( new int[1] );
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) ); BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[]> >()( p1 ), std::hash< int* >()( p1.get() ) );
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) ); BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[]> >()( p2 ), std::hash< int* >()( p2.get() ) );
} }
{ {
boost::hash< boost::local_shared_ptr<int[1]> > hasher;
std::hash< boost::local_shared_ptr<int[1]> > hasher2;
boost::local_shared_ptr<int[1]> p1, p2( new int[1] ); boost::local_shared_ptr<int[1]> p1, p2( new int[1] );
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) ); BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[1]> >()( p1 ), std::hash< int* >()( p1.get() ) );
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) ); BOOST_TEST_EQ( std::hash< boost::local_shared_ptr<int[1]> >()( p2 ), std::hash< int* >()( p2.get() ) );
} }
return boost::report_errors(); return boost::report_errors();

View File

@@ -3,7 +3,6 @@
// https://www.boost.org/LICENSE_1_0.txt // https://www.boost.org/LICENSE_1_0.txt
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/functional/hash.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
#include <functional> #include <functional>
@@ -17,33 +16,24 @@ int main() {}
int main() int main()
{ {
{ {
boost::hash< boost::shared_ptr<int> > hasher;
std::hash< boost::shared_ptr<int> > hasher2;
boost::shared_ptr<int> p1, p2( new int ); boost::shared_ptr<int> p1, p2( new int );
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) ); BOOST_TEST_EQ( std::hash< boost::shared_ptr<int> >()( p1 ), std::hash< int* >()( p1.get() ) );
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) ); BOOST_TEST_EQ( std::hash< boost::shared_ptr<int> >()( p2 ), std::hash< int* >()( p2.get() ) );
} }
{ {
boost::hash< boost::shared_ptr<int[]> > hasher;
std::hash< boost::shared_ptr<int[]> > hasher2;
boost::shared_ptr<int[]> p1, p2( new int[1] ); boost::shared_ptr<int[]> p1, p2( new int[1] );
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) ); BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[]> >()( p1 ), std::hash< int* >()( p1.get() ) );
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) ); BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[]> >()( p2 ), std::hash< int* >()( p2.get() ) );
} }
{ {
boost::hash< boost::shared_ptr<int[1]> > hasher;
std::hash< boost::shared_ptr<int[1]> > hasher2;
boost::shared_ptr<int[1]> p1, p2( new int[1] ); boost::shared_ptr<int[1]> p1, p2( new int[1] );
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) ); BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[1]> >()( p1 ), std::hash< int* >()( p1.get() ) );
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) ); BOOST_TEST_EQ( std::hash< boost::shared_ptr<int[1]> >()( p2 ), std::hash< int* >()( p2.get() ) );
} }
return boost::report_errors(); return boost::report_errors();