Boost logo

Boost :

From: nbecker_at_[hidden]
Date: 2002-01-29 08:03:04

I'm trying to learn to use iterator helpers, but I need a little
help. The only example I found I don't understand. Maybe I need a
more basic example.

I'm trying a simple example. The class "fifo" has a circular buffer
with seperate read and write pointers. I'd like to implement
begin_r(), end_r(), begin_w(), and end_w() which will give appropriate
iterators for read and write.

BTW, here is fifo:

#ifndef fifo_H
#define fifo_H

#include <vector>
using std::vector;

template<typename in_t>
class fifo {

  fifo (size_t size, initReadIndex = 0, initWriteIndex = 0) :
    dat (size+1),
    read_index (initReadIndex),
    write_index (initWriteIndex)

  void Write (in_t x, int i) {
    dat[index (i + write_index)] = x;

  in_t Read (int i) {
    return dat[index (i + read_index)];

  void AdvWrIndex (int i) {
    write_index += i;

  void AdvRdIndex (int i) {
    read_index += i;


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

  vector<in_t> dat;
  size_t allocated;
  int write_index;
  int read_index;


Boost list run by bdawes at, gregod at, cpdaniel at, john at