mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-10-22 04:11:41 +02:00
72 lines
1.2 KiB
C++
72 lines
1.2 KiB
C++
![]() |
// Copyright 2011, 2020 Peter Dimov
|
||
|
// Distributed under the Boost Software License, Version 1.0.
|
||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||
|
|
||
|
#include <boost/intrusive_ptr.hpp>
|
||
|
#include <boost/functional/hash.hpp>
|
||
|
#include <boost/core/lightweight_test.hpp>
|
||
|
#include <boost/config.hpp>
|
||
|
#include <functional>
|
||
|
|
||
|
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
||
|
|
||
|
int main() {}
|
||
|
|
||
|
#else
|
||
|
|
||
|
class base
|
||
|
{
|
||
|
private:
|
||
|
|
||
|
int use_count_;
|
||
|
|
||
|
base(base const &);
|
||
|
base & operator=(base const &);
|
||
|
|
||
|
protected:
|
||
|
|
||
|
base(): use_count_(0)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
virtual ~base()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public:
|
||
|
|
||
|
long use_count() const
|
||
|
{
|
||
|
return use_count_;
|
||
|
}
|
||
|
|
||
|
inline friend void intrusive_ptr_add_ref(base * p)
|
||
|
{
|
||
|
++p->use_count_;
|
||
|
}
|
||
|
|
||
|
inline friend void intrusive_ptr_release(base * p)
|
||
|
{
|
||
|
if(--p->use_count_ == 0) delete p;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct X: public base
|
||
|
{
|
||
|
};
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
boost::hash< boost::intrusive_ptr<X> > hasher;
|
||
|
std::hash< boost::intrusive_ptr<X> > hasher2;
|
||
|
|
||
|
boost::intrusive_ptr<X> p1, p2( new X );
|
||
|
|
||
|
BOOST_TEST_EQ( hasher( p1 ), hasher2( p1 ) );
|
||
|
BOOST_TEST_EQ( hasher( p2 ), hasher2( p2 ) );
|
||
|
|
||
|
return boost::report_errors();
|
||
|
}
|
||
|
|
||
|
#endif // #if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|