I think the problem is more general than a single == operator.
The == operator is closely related to != And may be attached to < , > , <= and >= .
The definition must be consistent among all of them, that is, either two arrays of different sizes can be compared (regardless of the comparison used), or this is not so.
I suspect both may be helpful:
- compile-time error: you are warned that there is something suspicious here.
- runtime-time false: you do not need to specialize all your template methods for different sizes.
But only one gives a warning at compile time, the other means that you hope to detect a problem at runtime (through testing). Therefore, I would provide a “safe” operator overload and a more detailed method for a “soft” comparison:
template <typename T, size_t M, size_t N> bool soft_equal(array<T,M> const& lhs, array<T,N> const& rhs) { if (M != N) { return false; }
So you get the best of both worlds, I think:
- Compilation caution warning
- A compile-time error can be easily handled if it is intended to
Guideline: make it easy to understand and hard to make a mistake
source share