I'm wondering if a if
statement or a return
quits early if possible. E.g. in this code:
bool Point::operator==(const Point &rhs) const
{
return (x==rhs.x //if the x's are not equal, there's no point in comparing y and z.
&& y==rhs.y
&& z==rhs.z);
}
or this:
bool Point::operator==(const Point &rhs) const
{
if (x==rhs.x //same as above
&& y==rhs.y
&& z==rhs.z)
return true;
return false;
}
Further, is any one of the above version better?