A while back I published an article in the (late, much missed) CUJ
describing a List container that used two-way pointers to implement an
STL-like container with "fickle-forward" iterators. The primary goal
of that article was to illustrate the continued value of bitwise
operators in advanced C++ programming.
However, I've been thinking about List and its weird iterators on and
off since then. As an exercise for my advanced STL course, I decided
to turn List into a fully-compliant STL container. The results were
pleasing:
The new container is called "flist," which is pronounced "ef list."
The "f" stands for "fickle."
flist has the same functionality as std::list (splice, merge, sort,
remove_if, etc.)
flist uses half the working storage of std::list, with equivalent
performance. This implementation of flist also seems to cause less
code bloat than (at least some implementations of) std::list for many
instantiations with different element types.
flist has "fickle-bidirectional" iterators that can easily change
their mind about which way they're traversing. (It also has
reverse_iterators, but they have different properties.)
flist has a constant-time reverse operation.
The major functional difference between std::list and flist is in
iterator invalidation. flist is not a "node-based" container (even
though it's implemented with nodes) because inserting or erasing an
element may affect iterators to adjacent elements. However, like
std::deque, pointers and references to adjacent elements are unaffected.
The source code for flist may be found on Semantics Consulting's code
page: <http://www.semantics.org/code.html#flist>. Comments at the
head of the file give more information about the container, and I hope
to have documentation and usage examples available soon.
Steve