|
Boost Users : |
Subject: Re: [Boost-users] [boost-users] istream_iterator question - need Steven's help
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-05-17 00:47:33
AMDG
Max wrote:
> const _Ty& operator*() const
> { // return designated value
> return (_Myval);
> }
>
> _Myt& operator++()
> { // preincrement
> _Getval();
> return (*this);
> }
>
> IMO, it should be modified as:
>
> const _Ty& operator*() //const
> { // return designated value
> _Getval();
> return (_Myval);
> }
>
> _Myt& operator++()
> { // preincrement
> return (*this);
> }
>
> The main problem of the current design of istream_iterator is that
> it always swallow one extra object, of the template parameter
> type, prepared for the coming * or -> operator. This makes the
> coming plain >> operator a distance forward of where it shoud be.
>
> I've tested with this modification and found it works well. Please
> note that I've simply commented out the trailing const qualifier
> for the * and -> operator, to make things simpler and more
> straightforward. Obviously, furthur modification is to be made to
> make the code to a product level.
>
> I want to know whether this change makes sense?
>
Well, it solves your problem, but it creates other problems instead.
For example, what should this do:
std::istream_iterator<int> iter(std::cin);
std::advance(iter, 10);
Or this:
std::istream_iterator<int> iter(std::cin);
if(*iter != 10) {
std::cout << *iter;
}
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net