forked from boostorg/smart_ptr
Add hash_value for shared_ptr; prevents hash_value( bool ) from being used. Refs #5216.
[SVN r69260]
This commit is contained in:
@ -41,6 +41,7 @@
|
||||
#include <algorithm> // for std::swap
|
||||
#include <functional> // for std::less
|
||||
#include <typeinfo> // for std::bad_cast
|
||||
#include <cstddef> // for std::size_t
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM)
|
||||
#if !defined(BOOST_NO_IOSFWD)
|
||||
@ -722,7 +723,16 @@ template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> *
|
||||
return atomic_compare_exchange( p, v, w ); // std::move( w )
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
|
||||
|
||||
// hash_value
|
||||
|
||||
template< class T > struct hash;
|
||||
|
||||
template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p )
|
||||
{
|
||||
return boost::hash< T* >()( p.get() );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
@ -65,5 +65,6 @@ import testing ;
|
||||
[ run atomic_count_test2.cpp ]
|
||||
[ run sp_typeinfo_test.cpp ]
|
||||
[ compile make_shared_fp_test.cpp ]
|
||||
[ run sp_hash_test.cpp ]
|
||||
;
|
||||
}
|
||||
|
34
test/sp_hash_test.cpp
Normal file
34
test/sp_hash_test.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// sp_hash_test.cpp
|
||||
//
|
||||
// Copyright 2011 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::hash< boost::shared_ptr<int> > hasher;
|
||||
|
||||
boost::shared_ptr< int > p1, p2( p1 ), p3( new int ), p4( p3 ), p5( new int );
|
||||
|
||||
BOOST_TEST_EQ( p1, p2 );
|
||||
BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) );
|
||||
|
||||
BOOST_TEST_NE( p1, p3 );
|
||||
BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) );
|
||||
|
||||
BOOST_TEST_EQ( p3, p4 );
|
||||
BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) );
|
||||
|
||||
BOOST_TEST_NE( p3, p5 );
|
||||
BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user