|
|
Line 61: |
Line 61: |
|
| |
|
| ==== Iterator handling ==== | | ==== Iterator handling ==== |
| * Our implementation of begin(/end) returning (const_)iterator is bugged, i.e. the current implementation for iterators of Common::List will not work with code like:
| |
| Common::List<int> list;
| |
| Common::List<int>::const_iterator x = list.begin();
| |
| It will fail with (i.e. gcc 4.2.3):
| |
| error: conversion from ‘Common::List<int>::Iterator<int>’ to non-scalar type ‘Common::List<int>::Iterator<const int>’ requested
| |
| To understand what is wrong you have to know that C++ does not support function overloading by return value, so it picks 'iterator Common::List<T>::begin' (NOT the implementation for constant instances of the type, since 'list' is not const in this example) instead of 'const_iterator Common::List<T>::begin' (the one for constant instances of the type). This is no problem at all for the STL, but since our 'Common::List::Iterator' implementation does not supply a copy constructor from 'Common::List<T>::Iterator<t_T2>' to 'Common::List<T>::Iterator<const t_T2>', it will fail. Check for example Common::HashMap::Iterator for a (rather hacky) implementation of it, or [http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/stl__tree_8h-source.html#l00221 the GNU libstdc++ implementation] (example for std::map iterators).
| |
| * Implement proper reverse_iterators for Common::List. Our current implementation is the same as forward iterators, just that rbegin will return the last element instead of the first and there is no rend. Check [http://www.sgi.com/tech/stl/ReverseIterator.html SGI Documentation] for proper description of revese_iterator in the STL. | | * Implement proper reverse_iterators for Common::List. Our current implementation is the same as forward iterators, just that rbegin will return the last element instead of the first and there is no rend. Check [http://www.sgi.com/tech/stl/ReverseIterator.html SGI Documentation] for proper description of revese_iterator in the STL. |
|
| |
|