Topic: C++0x Iterator Concept Relationships


Author: Scott Meyers <usenet@aristeia.com>
Date: Tue, 9 Jun 2009 15:47:00 CST
Raw View
Three questions about the relationships among iterator concepts in draft C++0x:
- Why does OutputIterator require Iterator instead of refining it?
- Why does ForwardIterator refine only InputIterator instead of both
InputIterator and OutputIterator?
- 24.2.7 says "A shuffle iterator is a form of forward and output
iterator," yet it refines neither concept and requires only
ForwardIterator. Why?

Thanks,

Scott

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: James Hopkin <tasjaevan@gmail.com>
Date: Wed, 10 Jun 2009 17:06:38 CST
Raw View
On Jun 9, 10:47 pm, Scott Meyers <use...@aristeia.com> wrote:
> Three questions about the relationships among iterator concepts in draft C++0x:
> - Why does OutputIterator require Iterator instead of refining it?
> - Why does ForwardIterator refine only InputIterator instead of both
> InputIterator and OutputIterator?
> - 24.2.7 says "A shuffle iterator is a form of forward and output
> iterator," yet it refines neither concept and requires only
> ForwardIterator. Why?
>

I think I can answer your middle question. The OutputIterator concept
has been defined orthogonally to the other iterator concepts. For
example, we can define a random access iterator whose operator*
returns by value; this iterator will only model RandomAccessIterator,
not OutputIterator.

I think you may have already pointed this out, but looking at the
March draft, the sequences' iterators are still specified with the
original wording, not using concepts. As I understand it, vector's non-
const iterators, for example, should be specified to model both
RandomAccessIterator and OutputIterator.

As for ShuffleIterator, it can't refine OutputIterator because the
point of it is to only require swappability or movability. The wording
where it says it's an output iterator is probably misleading.

I don't know why 'requires' is used in some cases, rather that
refinement, but I notice that both OutputIterator and ShuffleIterator
are auto concepts - perhaps there is an issue with auto concepts and
refinement.

James


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]