The C++ community has known for a long time that the STL iterator requirements are too strict. There have been various attempts at refactoring the iterator concepts to loosen the requirements (thus permitting more iterator-like entities to be iterators).
In Oxford, Jeremy Siek presented an alternative iterator concept taxonomy that separated access from traversal (the main known issue with the existing iterator requirements), describing using Concepts. Better yet, he updated all of the STL algorithms to use this new concept taxonomy, proving how well it works.
Since then, Jeremy Siek and Alex Stepanov realized that an even simpler change would suffice: in the existing iterator concepts, as modeled by ConceptGCC up until a few days ago, dereferencing a ForwardIterator had to return a “true” C++ reference (e.g., value_type const&) . It turns out that this requirement is very, very rarely used in the STL. So, Jeremy made a very simple change: ForwardIterators, like InputIterators, only require that operator* return something convertible to value_type. Mutable iterators require that one can assign a value_type to the result of operator*. Now, proxy iterators (like the infamous vector<bool>::iterator) can meet all of the iterator concept requirements!
ConceptGCC now has these new, old iterator concepts. With just a minor change, Jeremy and Alex fixed the major problems with iterator concepts… and it’s completely implemented in the development verson of ConceptGCC. Huzzah!
May 15, 2007 at 1:09 pm |
I was able to solve with this version of ConceptGCC the (infamous also) problem of sorting two “parallel” vectors, in an eventually conforming way!
If you have two vectors (vector, vector) and you like to treat them as a unified structure(as an alternative to map for example) the most natural way is to make up an iterator with value type something like pair and reference_type pair (that is not value_type&). Unfortunately this solution was not conforming. I was able to compile such an iterator with this version of ConceptGCC and it worked just fine.
It had been working also with gcc 4.1.1 (and older i think) but it was not a portable solution.
It was my fist time testing ConceptGCC and I thing the compilation speed is going to be a real problem.
May 16, 2007 at 10:07 am |
Something went wrong with the conversion of my previous message and template brackets and parameters disappeared. So I repeat it hopefully correct this time
I was able to solve with this version of ConceptGCC the (infamous also) problem of sorting two “parallel” vectors, in an eventually conforming way!
If you have two vectors (
vector<key_type> , vector<data_type>) and you like to treat them as a unified structure(as an alternative tomap<key_type, data_type>for example) the most natural way is to make up an iterator with value type something likepair<key_type, data_type>and reference_typepair<key_type& , data_type& >(that is not value_type&). Unfortunately this solution was not conforming. I was able to compile such an iterator with this version of ConceptGCC and it worked just fine.It had been working also with gcc 4.1.1 (and older i think) but it was not a portable solution.
It was my fist time testing ConceptGCC and I thing the compilation speed is going to be a real problem.