Skip to content

Instantly share code, notes, and snippets.

@kmichel
Created January 26, 2014 21:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmichel/8639972 to your computer and use it in GitHub Desktop.
Save kmichel/8639972 to your computer and use it in GitHub Desktop.
Ugly custom operator
#include <iostream>
class DotOp {
};
class LhsDotOp {
public:
int value;
explicit LhsDotOp(int value) : value(value) {}
};
// Of course you should have vector instead of int and the real operation instead of + ;)
LhsDotOp operator*(int value, DotOp) {
return LhsDotOp(value);
}
int operator*(LhsDotOp lhs_dot_op, int value) {
return lhs_dot_op.value + value;
}
#define DOT * DotOp() *
int main(int, char**) {
std::cout << 42 DOT 34;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment