Log for the design of a statically safe list<J*>
Yesterday, I thought that the current_
member of
JList::iterator poses me a problem, which I cannot quite find
again today:
- I have to compare it when comparing iterators (two iterators
could differ only by their current_ member)
- To detect that a list is empty, one can only compare the
begin() and end() iterators for equality.
- Thus, iterators pointing at the beginning or the end of an empty
list must be identical.
- I am allowed to invalidate iterators pointing to the element I
am erasing. If I erase the last element (the list becomes
empty), I don't care for iterators pointing at it.
- True, but I do care for an iterator that would be pointing
past it, i.e. at the end of the list. And I am not
allowed to modify it. I.e. its current_ must not change
because the list becomes empty.
- Therefore, there cannot be a special empty_ state in
the Current enum (the solution followed yesterday in
the /main branch).
- Furthermore, the iterator returned by end() must have a
fixed current_ value (conventionally, string_).
- Therefore, the iterator returned by begin() from an
empty list must have the same current_ value
(string_).
I initiated yesterday 2 alternative modification strategies:
- the one based on an empty_ state (in the /main
branch) is clearly wrong;
- the other (in a no_current branch) is not definitely to
be abandoned, but is only an option. I leave it for now (both
incompleted and in error!)
I continue thus for now on the /main branch, but undo the
empty_ changes.
Completed, built: it works.
Labelled MARC-JLIST-002.
Logs ToC
Marc Girod
Last modified: Mon Mar 27 10:21:27 EETDST 2000