Add .owner_hash_value to shared/weak_ptr, hash_value, std::hash/equal_to specializations for weak_ptr

This commit is contained in:
Peter Dimov
2020-06-04 20:40:57 +03:00
parent bc677e9098
commit 5dd84ea389
8 changed files with 308 additions and 31 deletions

61
test/wp_hash_test2.cpp Normal file
View File

@@ -0,0 +1,61 @@
// Copyright 2011, 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/weak_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <functional>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
int main() {}
#else
int main()
{
{
boost::shared_ptr<int> p1, p2( new int );
boost::weak_ptr<int> q1( p1 ), q2( p2 ), q3;
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q1 ), q1.owner_hash_value() );
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q2 ), q2.owner_hash_value() );
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q3 ), q3.owner_hash_value() );
p2.reset();
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q2 ), q2.owner_hash_value() );
}
{
boost::shared_ptr<int[]> p1, p2( new int[1] );
boost::weak_ptr<int[]> q1( p1 ), q2( p2 ), q3;
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q1 ), q1.owner_hash_value() );
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q2 ), q2.owner_hash_value() );
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q3 ), q3.owner_hash_value() );
p2.reset();
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q2 ), q2.owner_hash_value() );
}
{
boost::shared_ptr<int[1]> p1, p2( new int[1] );
boost::weak_ptr<int[1]> q1( p1 ), q2( p2 ), q3;
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q1 ), q1.owner_hash_value() );
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q2 ), q2.owner_hash_value() );
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q3 ), q3.owner_hash_value() );
p2.reset();
BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q2 ), q2.owner_hash_value() );
}
return boost::report_errors();
}
#endif // #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)