|
Tech Talk
Designing
C++ Iterators
Iterator Categories
Trends
SD'2000
What's Hot, What's Not
Lost Boys
Whisper Programmer Studio
VMWare v2.0
Editorial
My
Mistake + Apologies
Name Change
|
By Reg. Charney
If you plan to design a container class of objects, you often
want to access each element of the container. Iterators can do this.
Here is a simple recipe for creating iterators for your containers:
- Containers are classes that contain zero, one or more
elements.
- An iterator is a class that can be used to access each
member of its associated container.
- Iterators (I) are intimately associated with their container
classes (C). Thus, iterators are defined as nested public
classes (C::I) inside their related container classes.
- Due to C++ access rules, iterators and container classes are
often mutual friend classes of
each other.
- In C++, iterators are often treated as generalized pointers.
The following operations are defined on iterators: *(dereference),
->,
++, ==, !=, The copy,
and assignment operators are also defined, if they make sense.
- There must be two container class member functions : C::begin()
and C::end() in each container
class that has iterators, .
- C::end() returns an iterator
pointing “one past” the last element of the container.
Often C::end() returns a
default iterator. C::begin()
returns an iterator pointing to the first element in the
container. If the container is empty, C::begin()
returns the value of C::end().
The C::begin() member function
connects the this pointer for the
container with each defined iterator.
To save space below, many normal member functions have been
omitted from this executable example.
Iterators come in five categories, remembered using the acronym
BRIEF: Bi-directional, Random, Input, Emit/output, and Forward.
Input iterators:
- One pass, forward only.
- Can’t be dereferenced, copied or assigned.
- No write access
- No lvalue, can be on the left hand side of an assignment
Emit/Output Iterators
- One pass, forward only.
- Dereferencing only on the left hand side of an assignment.
- No read access
- Usually only one output iterator instantiated at a time
Forward Iterators
- Can move forward.
- Iterator values can be stored and retrieved – can be
dereferenced on left or right side of an assignment.
Bi-Directional Iterators
- Have all the attributes of Forward iterators, and can move
backwards.
Random Iterators
- Have all attributes of Bi-Directional iterators plus are able
to access entries in the container in any order. Member function
at() and operator[]
are defined.
The container’s design solely determines the category of
iterator. You can not impose an iterator or iterator category onto a
container from the outside.
Material for designing iterators can be found in Designing
Components with the C++ STL by Ulrich Breymann, Addison-Wesley,
ISBN 0-201-67488-2. And again, Nicolai M. Josuttis’s The C++
Standard Template Library, Addison-Wesley, ISBN 0-201-37926-0 is
also an excellent source for examples and information on iterators.
Iterator
Example
By Reg. Charney
I have had a lot of fun designing,
creating, and writing this newsletter. But in the last issue, I had
gone too far and I was not serving you and for this I offer my
apologies. Last month’s editorial comment was the largest part of
the newsletter. It did not start out that way, but time and other
factors got in the way. I also realized that in my first issue, I
promised to be pithy, to the point and technically oriented. Again,
that did not happen, except for the excellent technical article by
Michael Ball on Compile-Time Template Calculations. Lastly, the
technical content was almost buried on page three. All in all, not a
good way to go.
So I am now going to make a commitment to
you. One that is measurable and one that I can use as a benchmark.
The editorial content of the newsletter will be limited to one
column in this four-page format (i.e., 12% of the newsletter).
Second, the technical articles are going to have pride of place.
Each newsletter will start with technical material, not editorial,
on page one. The editorial will not appear on page one unless really
extraordinary circumstances dictate that it do so. Lastly, some form
of the newsletter will appear on the web, hopefully, by the time you
read this.
This newsletter is here to serve you, so
let’s hear your feedback – good or bad . Please let us know how
best to do this.
Recently, I have had some negative comments to the name ACCU’SiVe.
It sounded too much like j’accuse – which some Frenchman, Victor
Hugo, has already taken. We have received some suggestions, but want
more. Starting with this issue, ACCU’SiVe has been renamed
ACC++ent. However, if you have a better name, let us know.
By Reg. Charney
The Software Development 2000 Conference in San Jose has just finished, so
instead of doing job market statistics, I thought you might be interested in the
changes over the last year in a number of show categories.
Measurement was by counting vendors and the categories that they represented.
There were some changes in categories from 1999 to 2000. For example, no one
advertises 3GLs any longer, while middleware is a new category in 2000. The only
major positive change was that the number of vendors offering client/server
solutions increased. Comparing categories is difficult because one can argue
about material changes as opposed to buzzword changes.
Even though the numbers were smaller than last year, the courses offered were
very good— especially the tutorials. I was also surprised by some of the
exhibits, which I will discuss next.

Figure #1

Figure #2
Lost Boys
This was the most visually impressive product I saw. Lost Boys’ multimedia
C++ development environment is smooth, powerful and seems easy to use and
program. It works on a whole range of machines, from old Pentiums to the latest
speed demons, under Windows, Linux, BeOS and MacOS. They are from the
Netherlands. Their demo of Anne Frank’s house is spectacular. You can find
them at www.lostboys.com. Their website is also a treat.
Whisper Programmer Studio
These U.K. folks have a very nice IDE that is platform independent. Their
features match the most sophisticated ones on Windows. It is also compiler and
tool independent. You can find them at www.wispertech.com.
VMWare v2.0
Although not a new product, the improvements and features of this product
make it an essential tool for developers. The ability to roll back changes and
maintain reference platforms is wonderful. See them at www.vmware.com.
|