Operator Overloading Tricks in C++ This method is taken from Syntactic Aspartame. This is my attempt at a generic version.

The goal is to create an operator X &lt;NAME&gt; Y where name is anything, and X, Y, and the return is of any type.

Here is the 'library':

#ifndef COMPUTERSCIENCE_ANGULAR_OPERATOR_H
#define COMPUTERSCIENCE_ANGULAR_OPERATOR_H

template &lt;typename LHS, typename RHS, typename RET&gt; struct AngularOperator;

template &lt;typename LHS, typename RHS, typename RET&gt;
struct InnerAngularOperator {
    const AngularOperator&lt;LHS, RHS, RET&gt;* outer;
    LHS* lhs;
    bool outer_l;

    RET operator&gt;(RHS&amp; rhs) {
        return (outer_l) ? outer-&gt;angular_lr(*lhs, rhs) : outer-&gt;angular_rr(*lhs, rhs);
    }

    RET operator&lt;(RHS&amp; rhs) {
        return (outer_l) ? outer-&gt;angular_ll(*lhs, rhs) : outer-&gt;angular_rl(*lhs, rhs);
    }
};

template &lt;typename LHS, typename RHS, typename RET&gt;
struct AngularOperator {
    explicit AngularOperator() { }

    virtual RET operator()(LHS&amp; lhs, RHS&amp; rhs) const = 0;
    virtual RET angular_lr(LHS&amp; lhs, RHS&amp; rhs) const { return operator()(lhs, rhs); }
    virtual RET angular_rr(LHS&amp; lhs, RHS&amp; rhs) const { return operator()(lhs, rhs); }
    virtual RET angular_ll(LHS&amp; lhs, RHS&amp; rhs) const { return operator()(lhs, rhs); }
    virtual RET angular_rl(LHS&amp; lhs, RHS&amp; rhs) const { return operator()(lhs, rhs); }
};

template &lt;typename LHS, typename RHS, typename RET&gt;
InnerAngularOperator&lt;LHS, RHS, RET&gt; operator&lt;(LHS&amp; lhs, const AngularOperator&lt;LHS, RHS, RET&gt;&amp; outer) {
    return {&amp;outer, &amp;lhs, true};
};

template &lt;typename LHS, typename RHS, typename RET&gt;
InnerAngularOperator&lt;LHS, RHS, RET&gt; operator&gt;(LHS&amp; lhs, const AngularOperator&lt;LHS, RHS, RET&gt;&amp; outer) {
    return {&amp;outer, &amp;lhs, false};
};

#endif //COMPUTERSCIENCE_ANGULAR_OPERATOR_H


And here is a simple implementation for string concatenation:

static const struct OP__ANG__STRING_CONCAT : AngularOperator&lt;std::string, std::string, std::string&gt; {
    std::string operator()(std::string&amp; lhs, std::string&amp; rhs) const override { return lhs + rhs; }
} C{};


And finally the usage of all of this would be:

std::string a = "123", b = "456";
std::string c = a &lt;C&gt; b;
// c == "123456
I think your approach is problematic, in the following senses:


You use inheritance for genericity. There's no good reason for there to be an abstract base class for such operations. The behavior of your class is compile-time-determined by the binary operator you which to represent, and nothing else.
You use virtual methods, which really have no bearing on the problem at hand. That is, I don't see any reason why such operators need vtables.
You template on the binary operator's parameter and result types, rather than the operator itself, i.e. instead of

template &lt;typename LHS, typename RHS, typename RET&gt;


try 

template &lt;typename Function&gt;


with std::return_type to obtain RET and so on.
Your infix operator implementation has state - and pointer state at that, which is difficult to optimize away - instead of just using temporary values which can get discarded. Don't be so stuck on imperative programming...


I'm pretty sure you could address all three of these issues with a more templated-oriented implementation; with an intermediate class for "infix operator after having gotten the LHS" (or after having gotten the RHS) which can then take the other operator. Possibly the CRTP is relevant here.

I'm being a bit brief and a bit philosophical since I'm strapped for time. If this is too vague for you (=OP), ask for clarification and I'll expand this answer later on.