This is what the original code says (in the book and source)
bool const operator == (optional const & other) const
{
if ((! valid()) && (! other.valid())) { return true; }
if (valid() ^ other.valid()) { return false; } // <--
return ((* * this) == (* other));
}
what I find strange is the second expresion, look at this truth table:
a | other | return
0 - 0 - 1 so returns false
1 - 0 - 1 so returns false
0 - 1 - 0 so executes next line even though a is not valid. !!
0 - 0 is taken care of by the previous line
are you sure it will work this way?
bool const operator == (optional const & other) const
{
if ((! valid()) && (! other.valid())) { return true; }
if (valid() ^ other.valid()) { return false; } // <--
return ((* * this) == (* other));
}
what I find strange is the second expresion, look at this truth table:
a | other | return
0 - 0 - 1 so returns false
1 - 0 - 1 so returns false
0 - 1 - 0 so executes next line even though a is not valid. !!
0 - 0 is taken care of by the previous line
are you sure it will work this way?