Created
January 26, 2014 21:57
-
-
Save kmichel/8639972 to your computer and use it in GitHub Desktop.
Ugly custom operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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