Yes, this is pretty easy:
#define CREATE_OPERATOR(OP) \ Vec& Vec::operator OP##= (const double x) \ { return apply([x](double y) { return x OP y; }); } CREATE_OPERATOR(+) CREATE_OPERATOR(-) CREATE_OPERATOR(*) CREATE_OPERATOR(/)
Of course, if you need to reuse this list of operator symbols several times, you can do it with the X macro trick
operators.hxx
OPERATOR(+) OPERATOR(-) OPERATOR(*) OPERATOR(/) #undef OPERATOR
your code
#define OPERATOR(OP) \ #include "operators.hxx"
Angew source share