|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-01-31 21:47:53
Robert Ramey <ramey_at_[hidden]> writes:
> I have a problem with the latest version of the new iterators.
> This is illustrated in the following example.
>
> #include <strstream>
> #include <iterator>
> #include <boost/iterator/counting_iterator.hpp>
>
> main(){
> std::istrstream is("abcdefg");
> typedef boost::counting_iterator<std::istream_iterator<char> > ci;
> const ci end = std::istream_iterator<char>(); // note the const !!!
I don't see why the const should be relevant.
> ci begin = std::istream_iterator<char>(is);
Hmm, the implicit conversions from istream_iterator to the
counting_iterator above are troubling. I think those constructors
should be explicit.
> unsigned int size;
>
> // the following should fail at compilation ?
Why? OK, maybe it would be better to make it fail because the
iterator is not in fact a random-access iterator.
> // in fact it compiles are returns a value of -7 !!!
> size = begin - end;
>
> // the following should compile and return a value of 7
> // in fact, it compiles but goes into an infinite loop
> size = end - begin;
> }
I don't see why you think the first should compile but the second
should not. If they're not random-access iterators, it seems to me
that there's no reason you should be able to subtract them in any
order. If they were random-access iterators, it would be unreasonable
to expect the compiler to detect which one had an earlier position
and disallow one subtraction.
> Note that this problem did not appear with the first release
> candidate.
>
> Also, if one follows the links from the main documentation page, one
> is directed to the documentation of the old iterators. This is
> extremely confusing. This has been pointed out before.
That's a serious problem which I'll fix immediately.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk