Sure. You can't "overwrite the default", you but you can provide your own overload that will have higher precedence:
#include <iostream>
#include <valarray>
bool operator==(const std::valarray<double>& a, const std::valarray<double>& b)
{
std::cout << "hi\n";
return true;
}
int main(int argc, char *argv[])
{
std::valarray<double> a, b;
a == b; // prints hi
}
Since operator==
is a non-member function template, a function that isn't a template will be preferred in overload resolution. The key is to make sure that everywhere you compare valarray
's, unqualified lookup will find this overload.
Of course, it's a lot safer to just write:
bool equals(const std::valarray<double>&, const std::valarray<double>&);