• 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/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 
main()12 int main() {}
13 
14 #else
15 
16 class base
17 {
18 private:
19 
20     int use_count_;
21 
22     base(base const &);
23     base & operator=(base const &);
24 
25 protected:
26 
base()27     base(): use_count_(0)
28     {
29     }
30 
~base()31     virtual ~base()
32     {
33     }
34 
35 public:
36 
use_count() const37     long use_count() const
38     {
39         return use_count_;
40     }
41 
intrusive_ptr_add_ref(base * p)42     inline friend void intrusive_ptr_add_ref(base * p)
43     {
44         ++p->use_count_;
45     }
46 
intrusive_ptr_release(base * p)47     inline friend void intrusive_ptr_release(base * p)
48     {
49         if(--p->use_count_ == 0) delete p;
50     }
51 };
52 
53 struct X: public base
54 {
55 };
56 
main()57 int 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