Is there a way to get the equality operators to work for comparing arrays of the same type?
For example:
int x[4] = {1,2,3,4};
int y[4] = {1,2,3,4};
int z[4] = {1,2,3,5};
if (x == y) cout << "It worked!"
I’m aware that as is, it’s just comparing pointer values – but I was hoping there’s some kind of typedef trick or something like that so it wouldn’t need a loop or a memcmp call.
You can use the standard
std::equalalgorithm (orstd::ranges::equalsince C++20):