Skip to content

Instantly share code, notes, and snippets.

@kmichel
Created January 26, 2014 21:57

Revisions

  1. kmichel created this gist Jan 26, 2014.
    28 changes: 28 additions & 0 deletions dot.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #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;
    }