English
Summary
Conclusions
Operators must preserve their expected domain meaning. An invariant makes value comparison consistent. Stream input must preserve the state on failure. Tests check both the result and the algebraic laws.
Self-check questions
- Which properties of an operator can’t be changed by overloading?
- When should an operator be a free function?
- Why does += return a reference, while + returns a value?
- How do strong, weak and partial ordering differ?
- Does a user-defined spaceship operator automatically create equality?
- What does friend give, and what doesn’t it give?
- Why are two versions of operator[] needed?
- How do prefix and postfix ++ differ?
- What does explicit operator bool mean?
- Why isn’t operator<< enough for std::println?
- How do you avoid a partial change with >>?
- Why does the order of fields matter for a defaulted comparison?
- What contract does m[row, column] have?
- When is a named method better than an operator?
- How do you check for overflow before an arithmetic operation?