id summary reporter owner description type status milestone component version severity resolution keywords cc 34 enhance shared_ptr with traits class mkvonarx Peter Dimov "{{{ I suggest introducing a traits class for the boost smart pointers (shared_ptr and shared_array only) that take over responsibility for reference counting: ref_count_traits. With such a design, every user of the boost smart pointers could add specific additional features like thread safety, objects knowing about being reference counted, objects handling reference counting themselves (but still be used via boost smart pointers) etc. The default implementation of ref_count_traits could look somehow like this: template class ref_count_traits { public: struct ref_counted_ptr { typedef long ref_count_counter_type; explicit ref_count_ptr_impl(T* p): px(p) { try { pn = new ref_count_counter_type(0); } catch(...) { delete p; throw; } } T* px; // contained pointer ref_count_counter_type* pn; // ptr to reference counter }; typedef ref_counted_ptr ref_count_ptr_type; static T* get(const ref_count_ptr_type& pr) { return pr.px; } static ref_count_counter_type count(const ref_count_ptr_type& pr) { return pr.pn; } static void inc(const ref_count_ptr_type& pr) { ++*pr.pn; } static void dec(const ref_count_ptr_type& pr) { if(--*pr.pn == 0) { delete pr.pn; delete pr.px; } } }; }}}" Feature Requests closed smart_ptr None Rejected