In numerical programming I frequently want to raise a number to a power inside an expression. This leads to code that has hundreds of occurrences of pow(x,2)
or something of the sort.
This clutters the code and makes it less readable and less easy to parse, especially when comparing written equations with code.
I want to write an operator for exponentiation in C++, if this is at all possible.
a^b == pow(a, b)
I've tried writing an overload for operator()(double, double)
or operator[](double, double)
(chosen because it binds tighter than (binary) *
. However I can't make it work.
Is something like this in any way possible?
Maybe preprocessor trickery?