0

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.

1 Answer 1

1

_M_stream == __x._M_stream has undefined behaviour if either _M_ok or __x._M_ok is false.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.