Sometimes I have structs such as this --
struct aggregate1 {
std::string name;
std::vector<ValueT> options;
size_t foobar;
// ...
};
-- where (in)equality is simply defined as (in)equality of all members: lhs_name == rhs_name && lhs_options == rhs_options && lhs_foobar == rhs_foobar
.
What's the "best" way to implement this? (Best as in: (Runtime-)Efficiency, Maintainability, Readability)
operator==
in terms ofoperator!=
operator!=
in terms ofoperator==
- Separate implementations for
==
and!=
- As member or as free functions?
Note that this question is only about the (in)equality ops, as comparison (<
, <=
, ...) doesn't make too much sense for such aggregates.