Prefix keyword to fix namespace

It’s mainly a matter of taste IMO, however as @everythingfunctional has mentioned previously:

There is a subtle semantic implication of operators over functions. Operators must have intent(in) arguments. Thus, the usage alone tells a reader that the argument is not modified. While it would be considered bad practice, a function could possibly modify its argument.

You can take the user-defined operator syntax quite far, see here: Utilization of user-defined operators in Fortran

Another aspect of user-defined operators which should be taken into account according to Stroustrup (C++ exceptions and alternatives):

Operators – there is no place to return an error indicator from an operator, e.g., from
++, *, or ->. You will have to use non-local error indicators or live with an impoverished
notation, e.g., multiply(add(a,b),c) rather than (a+b)*c.

The solution in C++ in this case are exceptions.

3 Likes