I would favor having a comparison operator yield a chainable comparison result which can be implicitly converted to Boolean or used in an overload of the comparison operators. While chained comparisons are most commonly used to check whether one thing is within the range of two others, a single function would suffer from at least three significant limitations:
Sometimes the range should include the right and and sometimes not, and the range should occasionally exclude the left edge.
While checking for ordering among three items may be the most common use case, it's not particularly uncommon to require that four or more items be properly sequenced, e.g. checking whether
a <= b,
b <= c, and
c <= d are all true, but perhaps with some
<= replaced with
It's also not uncommon to want to check that multiple things are all equal to each other, and for this usage case checking three items would not be particularly more common than checking four. Note that if a compiler wants to include particular logic for it, a multi-way comparison may be faster than a sequence of individual comparisons on some platforms. For example, on an 8-bit platform, checking multiple
long values against each other might be done most efficiently by comparing the least-significant byte of every value, and then the next byte of every value, etc.
BTW, an alternative approach to passing code to evaluate the left-hand operand might be to provide a mechanism via which an expression can exit via one of two paths. This would be awkward at the source code level, but could make things nice at the compiler level. If something like:
if (expr1) ...action1...; else ...action2...;
calling an "evaluate branching instruction" with
action2 as the true and false targets, processing something like:
if (expr1 || expr2) ...action1...; else ...action2...;
pipeOperator(leftExpr, rightExpr, trueAction, falseAction); would involve
branchOperator(leftExpr, trueAction, branchOperator(rightExpr, trueAction, falseAction)). It might be possible to process chainable comparison operators similarly.