Boost logo

Boost :

From: Neal D. Becker (ndbecker2_at_[hidden])
Date: 2004-04-12 10:22:36


I'm looking at circular_buffer. It appears to me that operator[] uses
"add", and that "add" only allows a positive value of offset? It is not
difficult to allow arbitrary values, and this is very useful.

if "position" is the current "m_first" and "allocated" is the allocated
buffer size, the index could be calculated:

  int index (int offset) const {
    int x = (offset + position) % int(allocated);
    if (x >= 0)
      return x;
    else
      return x + allocated;
  }
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk