Thursday, 20 November 2008

C++: An STL-like circular buffer (Part 3)


Now it's time flesh out the class, and consider the interface we'd like to give it.

First, STL containers have a number of requirements, laid down in the C++ standard in section 23.1. This includes definitions for these nested type definitions:
  • value_type - type of the items help in the container
  • reference - type of a reference to an item in the container
  • const_reference - type of a reference to a constant item in the container
  • iterator - type of container iterator
  • const_iterator - type of container const interator
  • difference_type - type expressing the distance between two iterators (or const_iterators)
  • size_type - type that represents any non-negative value of difference_type
As a first step, we'll add to our class the following typedefs, remembering that T is the template parameter name for the container item type:
typedef T value_type;
typedef size_t size_type;
typedef int difference_type;
typedef value_type &reference;
typedef const value_type &const_reference;
This is a starting point. We'll define the iterator types later, and some of these definitions can be made a little more elegant, too.

Next time: we'll decide the mechanics of the class and how to manage resources.

1 comment:

Anonymous said...

thanks man, this is very useful for a noob like me.