Re: Testing new iterator concepts with ConceptGCC
on Thu May 17 2007, kostas <skolarik-AT-gmail.com> wrote:
I had considered once to replace a map not just with a sorted vector
but, for some efficiency reasons, with two "parallel"
vectors(vector<key_type>, vector<data_type>). It came natural to me to
make up an iterator with value_type something like pair<key_type,
data_type> and reference type pair<key_type&, data_type&>.
c.f. http://www.boost.org/libs/iterator/doc/zip_iterator.html
Unfortunately this is obviously not a valid forward iterator.
Right.
Well, I was able to compile such an iterator with the new version of
ConceptGCC (that claims to support proxy iterators) and it worked just
fine(at least with the sort algorithm).
I believe that's because of the following in the ForwardIterator
concept:
// Note: The standard specifies an exact requirement, but in this
// case there can be no refinement relationship between mutable and
// non-mutable iterators. We want that relationship, and the
// standard needs it, so we choose to require convertibility.
requires Convertible<reference, const value_type&>;
But is really going to be a
valid mutable random-access iterator according to new iterator
concepts?
No, but that's an old iterator concept. It would be a valid mutable
random access _traversal_ iterator.
There are two problems i can think of. First the requirement that
a==b iff *a, *b are the same object for forward iterators a,b.
Yeah, that's undetectable by the compiler ;-)
Good question though.
And second, the constrain imposed by ConceptGCC that the pointer of
the iterator must be convertible to value_type*. This does not make
sense for this iterator because iter->second must be equivalent to
(*iter).second and thus the pointer must be reference*.
I think that might be why I never wanted to require that operator->
return the pointer type.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
Don't Miss BoostCon 2007! ==> http://www.boostcon.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]