• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011, 2020 Peter Dimov
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #include <boost/weak_ptr.hpp>
6 #include <boost/shared_ptr.hpp>
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/config.hpp>
9 #include <functional>
10 
11 #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
12 
main()13 int main() {}
14 
15 #else
16 
main()17 int main()
18 {
19     {
20         boost::shared_ptr<int> p1, p2( new int );
21         boost::weak_ptr<int> q1( p1 ), q2( p2 ), q3;
22 
23         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q1 ), q1.owner_hash_value() );
24         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q2 ), q2.owner_hash_value() );
25         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q3 ), q3.owner_hash_value() );
26 
27         p2.reset();
28 
29         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int> >()( q2 ), q2.owner_hash_value() );
30     }
31 
32     {
33         boost::shared_ptr<int[]> p1, p2( new int[1] );
34         boost::weak_ptr<int[]> q1( p1 ), q2( p2 ), q3;
35 
36         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q1 ), q1.owner_hash_value() );
37         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q2 ), q2.owner_hash_value() );
38         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q3 ), q3.owner_hash_value() );
39 
40         p2.reset();
41 
42         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[]> >()( q2 ), q2.owner_hash_value() );
43     }
44 
45     {
46         boost::shared_ptr<int[1]> p1, p2( new int[1] );
47         boost::weak_ptr<int[1]> q1( p1 ), q2( p2 ), q3;
48 
49         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q1 ), q1.owner_hash_value() );
50         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q2 ), q2.owner_hash_value() );
51         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q3 ), q3.owner_hash_value() );
52 
53         p2.reset();
54 
55         BOOST_TEST_EQ( std::hash< boost::weak_ptr<int[1]> >()( q2 ), q2.owner_hash_value() );
56     }
57 
58     return boost::report_errors();
59 }
60 
61 #endif // #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
62