Reputation: 1
Can someone please explain why this istream_iterator code.
// code extract from SGI STL istream_iterator class
bool _M_equal(const istream_iterator& __x) const {
return (_M_ok == __x.M_ok) && (!_M_ok || _M_stream == __x._M_stream);
}
works and is not just written as
bool _M_equal(const istream_iterator& __x) const {
return (_M_ok == __x.M_ok) && (_M_stream == __x._M_stream);
}
I don't understanding the reason for including !_M_ok. Thanks in advance.
Upvotes: 0
Views: 35
Reputation: 63152
_M_stream == __x._M_stream
has undefined behaviour if either _M_ok
or __x._M_ok
is false.
Upvotes: 1