Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class Owner>
- class ref_counted
- {
- public:
- ref_counted() : m_ref_count(new unsigned long()) {}
- ~ref_counted() {if(!(*m_ref_count)--) { delete m_ref_count; Owner::destroy(d); }
- ref_counted(const ref_counted& that) {m_ref_count=that.m_ref_count; ++*m_ref_count;}
- void operator=(ref_counted that) {std::swap(m_ref_count, that.m_ref_count);}
- bool is_last_referrer() const {return *m_ref_count == 0;}
- private:
- unsigned long* m_ref_count;
- typename Owner::data d;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement