// DEPRECATED in favor of adl_postconstruct and adl_predestruct with // deconstruct(). // A factory function for creating a shared_ptr that enhances the plain // shared_ptr constructors by adding support for postconstructors // and predestructors through the boost::signals2::postconstructible and // boost::signals2::predestructible base classes. // // Copyright Frank Mori Hess 2007-2008. // // Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP #define BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP #include #include #include #include #include namespace boost { namespace signals2 { namespace detail { extern inline void do_postconstruct(const postconstructible *ptr) { postconstructible *nonconst_ptr = const_cast(ptr); nonconst_ptr->postconstruct(); } extern inline void do_postconstruct(...) { } extern inline void do_predestruct(...) { } extern inline void do_predestruct(const predestructible *ptr) { try { predestructible *nonconst_ptr = const_cast(ptr); nonconst_ptr->predestruct(); } catch(...) { BOOST_ASSERT(false); } } } template class predestructing_deleter { public: void operator()(const T *ptr) const { detail::do_predestruct(ptr); checked_delete(ptr); } }; template shared_ptr deconstruct_ptr(T *ptr) { if(ptr == 0) return shared_ptr(ptr); shared_ptr shared(ptr, boost::signals2::predestructing_deleter()); detail::do_postconstruct(ptr); return shared; } template shared_ptr deconstruct_ptr(T *ptr, D deleter) { shared_ptr shared(ptr, deleter); if(ptr == 0) return shared; detail::do_postconstruct(ptr); return shared; } } } #endif // BOOST_SIGNALS2_DECONSTRUCT_PTR_HPP