I think your approach is problematic, in the following senses:
- You use inheritance for genericity.
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 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
You template on the binary operator's parameter and result types, rather than the operator itself, i.e. instead of
template <typename LHS, typename RHS, typename RET>try
template <typename Function>with
std::return_typeto obtainRETand 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...
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.