I want to add one more thing: After my personal frustration about the default behavior of certain operators on built-in types, I wondered if it was possible to override that operators in a simple and readable way. The answer was my Polyop project, which achieves exactly that.
So, can you override the default behavior of C++ operators? Yes, just wrap them in a way that the operator call seems to be the same, but the thing its actually calling a completely different operator with the properties and behavior you defined.
//Redefine the behavior of the int vs int equality operator
auto operator==(void(int,int) , pop::default_context )
{
return [](int lhs , int rhs )
{
return lhs * 2 == rhs;
};
}
using pop::triggers::_;
int main()
{
bool equal = _(4) == 2; //Returns true, since its the behavior we defined above
}
All with no performance hits at all.