Advertisement
Guest User

Untitled

a guest
Nov 8th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. template<class Owner>
  2. class ref_counted
  3. {
  4. public:
  5. ref_counted() : m_ref_count(new unsigned long()) {}
  6. ~ref_counted() {if(!(*m_ref_count)--) { delete m_ref_count; Owner::destroy(d); }
  7.  
  8. ref_counted(const ref_counted& that) {m_ref_count=that.m_ref_count; ++*m_ref_count;}
  9. void operator=(ref_counted that) {std::swap(m_ref_count, that.m_ref_count);}
  10.  
  11. bool is_last_referrer() const {return *m_ref_count == 0;}
  12. private:
  13. unsigned long* m_ref_count;
  14. typename Owner::data d;
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement