I am going through "Accelerated C++" working on the chapter where you roll your own containers (chap 11).
I tried modifying a simplified vector-like container that I built in an earlier exercise, but I realized all I had was a vector container disquised as a list.
The question remained, what's the best approach.
I ran across this FAQ while searching the web and in particular would like to know what it means to create a templated atomic event for each iteration.
Excerpt from
http://parashift.com/c++-faq-lite/containers.html section [34.5]:
"[3] Consider the entire iteration as an atomic event, and create a class template that embodies this event. This enhances performance by allowing the public access member functions (which may be virtual functions) to be avoided during the access, and this access often occurs within an inner loop. Unfortunately the class template will increase the size of your object code, since templates gain speed by duplicating code. For more, see [Koenig, "Templates as interfaces," JOOP, 4, 5 (Sept 91)], and [Stroustrup, "The C++ Programming Language Third Edition," under "Comparator"]."
Now here's my take on it:
I create a stand-alone generic function that acts on the container object for each access/insert/delete that I wish to do to the container.
That's fairly understandable, although not fully.
Question 1) What does that excerpt actually mean?
Here's another source of confusion:
For the vector-like class (Vec), I used three pointers: the head of the data, the end of the used data, and the end of the allocated data.
For the list, I know I need a Node (prev*/data*/next*) type of structure, however, I also know that lists allow you to dereference the iterator just like other containers. It looks like this:
1 2 3 4 5 6
|
// sorry for simple example
list<int> ages(3, 0);
...
list<int>::iterator ageIter = ages.begin();
int currentAge = *ageIter;
|
not this:
1 2 3 4 5
|
list<int> ages(3, 0);
...
list<int>::iterator ageIter = ages.begin();
int currentAge = ageIter->data;
|
Question 2) Do I overload operator * for the customer list class iterator to further dereference the current nodes data member value?
Feel free to answer either. Thanks.