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.

2 comments:

sundeep said...

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

lijialefw said...

Why was there no follow on bankruptcy then? The bailout of AIG FP went to (wow power leveling) hedge funds that bound credit swaps on Lehman failing or others betting on rating (wow power leveling) declines. AIG has drained over 100 billion from the government. Which had to go to (wow power leveling) those who bet on failures and downgrades. Many of whom (power leveling)were hedge funds. I-banks that had offsetting swaps needed the money from the AIG bailout or they would have been caught. Its an (wow powerleveling) insiders game and it takes just a little bit too much time for most people to think (wow gold) through where the AIG 100 billion bailout money went to, hedge funds and players, many of whom hire from the top ranks of DOJ, Fed, Treasury, CAOBO