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/intrusive_ptr.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <boost/config.hpp>
8#include <functional>
9
10#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
11
12int main() {}
13
14#else
15
16class base
17{
18private:
19
20 int use_count_;
21
22 base(base const &);
23 base & operator=(base const &);
24
25protected:
26
27 base(): use_count_(0)
28 {
29 }
30
31 virtual ~base()
32 {
33 }
34
35public:
36
37 long use_count() const
38 {
39 return use_count_;
40 }
41
42 inline friend void intrusive_ptr_add_ref(base * p)
43 {
44 ++p->use_count_;
45 }
46
47 inline friend void intrusive_ptr_release(base * p)
48 {
49 if(--p->use_count_ == 0) delete p;
50 }
51};
52
53struct X: public base
54{
55};
56
57int main()
58{
59 boost::intrusive_ptr<X> p1, p2( new X );
60
61 BOOST_TEST_EQ( std::hash< boost::intrusive_ptr<X> >()( p1 ), std::hash< X* >()( p1.get() ) );
62 BOOST_TEST_EQ( std::hash< boost::intrusive_ptr<X> >()( p2 ), std::hash< X* >()( p2.get() ) );
63
64 return boost::report_errors();
65}
66
67#endif // #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
68

source code of boost/libs/smart_ptr/test/ip_hash_test2.cpp