more efficient
It is not related to what you do there (if by "effective" you mean the best characteristics of the execution time).
less
A humble goal, but not if, due to it, readability does not match (and even more so if, due to the syntactic complexity ... missing brackets ... the end result is incorrect).
Remember: code is written for people to read.
You should probably follow the if and else approach, which you also show in the question. However, IMHO the “good” approach (if you really need to ignore this) is to pack it into some function:
template<class T, class X, class Y, class Z> void comp_if(T value, T reference, X less, Y equal, Z greater) { if (value < reference) less(); else if (value > reference) greater(); else equal(); }
Used as
// missing real macros a lot comp_if(foo, bar, []() {cout << "less"; }, []() {cout << "equal";}, []() {cout << "greater"});
Whether this really helps with readability is the choice that I leave to the reader.
source share