Boost logo

Boost Users :

From: Alexander Gutenev (gutenev_at_[hidden])
Date: 2008-08-01 02:37:37


> I would add IncrementPolicy with following default.
>
> struct trivial_increment_policy {
> void inc( long& c ) { ++c; }
> bool dec( long& c ) { return --c == 0; }
> }
>
> Now you can add your own

I considered this, but for some reason there's no policies in shared_ptr, so
I decided not to add one too.
I think counter should belong to policy too (but no-copying is still up to
intrusive_pointee_base).

struct trivial_increment_policy {
   void inc() { ++c; }
   bool dec() { return --c == 0; }
   int c;
}

template<class Derived, template IncrementPolicy=trivial_increment_policy>
class intrusive_pointee_base
{
private:
  typedef intrusive_pointee_base self;

protected:
  intrusive_pointee_base(void) : reference_counter_() {}
  intrusive_pointee_base(self const&) : reference_counter_() {}
  self &operator=(self const&) { return *this }
  ~intrusive_pointee_base(void) {}
...
private:
   mutable IncrementPolicy reference_counter_;
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net