This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] libstdc++: istreambuf_iterator proxy
On Sun, 8 Oct 2017 16:59:39 +0200
François Dumont <frs.dumont@gmail.com> wrote:
> ...
> >>
> >> Consider this code:
> >>
> >> std::istringstream inf("abc");
> >> std::istreambuf_iterator<char> j(inf), eof;
> >> std::istreambuf_iterator<char> i = j++;
> >>
> >> assert( *i == 'a' );
> >>
> >> At this point it looks like i is pointing to 'a' but then when you do:
> >>
> >> std::string str(i, eof);
> >>
> >> you have:
> >> assert( str == "ac" );
> > No. I mean that in last (my) suggestion ([PATCH])
> >
> > std::istreambuf_iterator<char> i = j++;
> >
> > is impossible ("impossible" is in aggree with standard).
> > So test test01() in 2.cc isn't correct.
>
> It is correct as this constructor:
> + /// Construct start of streambuf iterator.
> + istreambuf_iterator(const proxy& __prx) _GLIBCXX_USE_NOEXCEPT
> + : _M_sbuf(__prx._M_sbuf)
> + { }
>
> is defined by the Standard. This is why the llvm test is fine too.
Yes, you right here.
But in
+ std::istringstream inf("abc");
+ std::istreambuf_iterator<char> j(inf);
+ std::istreambuf_iterator<char> i = j++;
+
+ VERIFY( i != std::istreambuf_iterator<char>() );
+ VERIFY( *i == 'b' );
+ VERIFY( *j++ == 'b' );
the last two lines
+ VERIFY( *i == 'b' );
+ VERIFY( *j++ == 'b' );
is a check of the implementation-specific behaviour, because of
++r ... any copies of the previous
value of r are no longer
required either to be
dereferenceable or to be in
the domain of ==.
...
(void)r++ equivalent to (void)++r
(i is a copy of "previous" value of j)
From other side, for ctor from proxy
istreambuf_iterator(const proxy& p) noexcept;
5 Effects: Initializes sbuf_ with p.sbuf_.
that mean that reference of istreambuf_iterator to basic_streambuf
(sbuf_) has some meaning. proxy may be dereferenced or used
to produce istreambuf_iterator that may be used for == (but not
for dereference itself ;)).