mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-07-31 21:24:40 +02:00
get_deleter<> added.
[SVN r16365]
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include <functional> // for std::less
|
#include <functional> // for std::less
|
||||||
#include <exception> // for std::exception
|
#include <exception> // for std::exception
|
||||||
#include <new> // for std::bad_alloc
|
#include <new> // for std::bad_alloc
|
||||||
|
#include <typeinfo> // for std::type_info in get_deleter
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
# pragma warn -8026 // Functions with excep. spec. are not expanded inline
|
# pragma warn -8026 // Functions with excep. spec. are not expanded inline
|
||||||
@@ -106,6 +107,8 @@ public:
|
|||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void * get_deleter(std::type_info const & ti) = 0;
|
||||||
|
|
||||||
void add_ref()
|
void add_ref()
|
||||||
{
|
{
|
||||||
#if defined(BOOST_HAS_THREADS)
|
#if defined(BOOST_HAS_THREADS)
|
||||||
@@ -253,6 +256,11 @@ public:
|
|||||||
del(ptr);
|
del(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void * get_deleter(std::type_info const & ti)
|
||||||
|
{
|
||||||
|
return ti == typeid(D)? &del: 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
|
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
|
||||||
|
|
||||||
void * operator new(std::size_t)
|
void * operator new(std::size_t)
|
||||||
@@ -371,6 +379,11 @@ public:
|
|||||||
{
|
{
|
||||||
return std::less<counted_base *>()(a.pi_, b.pi_);
|
return std::less<counted_base *>()(a.pi_, b.pi_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void * get_deleter(std::type_info const & ti) const
|
||||||
|
{
|
||||||
|
return pi_->get_deleter(ti);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __CODEGUARD__
|
#ifdef __CODEGUARD__
|
||||||
|
@@ -275,6 +275,11 @@ public:
|
|||||||
return pn < rhs.pn;
|
return pn < rhs.pn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void * _internal_get_deleter(std::type_info const & ti) const
|
||||||
|
{
|
||||||
|
return pn.get_deleter(ti);
|
||||||
|
}
|
||||||
|
|
||||||
// Tasteless as this may seem, making all members public allows member templates
|
// Tasteless as this may seem, making all members public allows member templates
|
||||||
// to work in the absence of member template friends. (Matthew Langston)
|
// to work in the absence of member template friends. (Matthew Langston)
|
||||||
|
|
||||||
@@ -364,6 +369,13 @@ template<class T> inline T * get_pointer(shared_ptr<T> const & p)
|
|||||||
return p.get();
|
return p.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get_deleter (experimental)
|
||||||
|
|
||||||
|
template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
|
||||||
|
{
|
||||||
|
return static_cast<D *>(p._internal_get_deleter(typeid(D)));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
|
Reference in New Issue
Block a user