
A poly_deleter really should not hold just a function pointer as a deleter. The custom deleter may be any function, containing any amount of state (it could for example be returning resources to a memory pool, or managing a semaphore). fixing the deleter type at `void (*)(void*)` is a no-go. It's not useful. On 21 March 2017 at 15:33, Andrey Semashev via Boost <boost@lists.boost.org> wrote:
On 03/21/17 16:33, Andrey Davydov wrote:
On Tue, Mar 21, 2017 at 4:11 PM, Andrey Semashev <andrey.semashev@gmail.com <mailto:andrey.semashev@gmail.com>> wrote:
struct poly_deleter { template< typename T > poly_deleter(T* p) : m_p(p), m_delete(&poly_deleter::do_delete< T >) { }
void operator() (void*) const noexcept { m_delete(m_p); }
private: template< typename T > static void do_delete(void* p) noexcept { delete static_cast< T* >(p); }
void* m_p; void (*m_delete)(void*); };
This will work even if you form std::unique_ptr<void, poly_deleter> (i.e. don't have a universal base class).
Your poly_deleter implementation is the same as I used inside my smart pointer implementation, but there is an issue with std::unique_ptr<T, poly_deleter>, namely it is not constructible from std::unique_ptr<T, std::default_delete<T>> because poly_deleter must capture pointer and so it is not constructible from std::default_delete.
I think that problem can be solved by make_poly_unique or a conversion helper function. Hardly a whole new smart-pointer is an adequate solution.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman /listinfo.cgi/boost