intrusive_ptr を楽に定義する
template<class Derived> class intrusive_ptr_facade { friend Derived; std::size_t ref_; friend inline void intrusive_ptr_add_ref(Derived* p) { ++static_cast<intrusive_ptr_facade<Derived>*>(p)->ref_; } friend inline void intrusive_ptr_release(Derived* p) { if (--static_cast<intrusive_ptr_facade<Derived>*>(p)->ref_ == 0) { delete p; } } intrusive_ptr_facade() : ref_(0) { } };
class hoge : public intrusive_ptr_facade<hoge> { }; intrusive_ptr<hoge> h(new hoge());
public 継承なのがダサすぎる……。