Assuming your operator >= produces a MyBool
type, I think you can get almost there with:
#define ? .ternary(
#define : )||
template <typename T>
T MyBool::ternary(T val) {
if (m_isTrue) return val;
return T(0)
}
Several things to note:
- This doesn't work for
a>=b
ifa
is 0 andb
is negative. - This is a terrible terrible hack that will break on many edge cases.
- You can't actually use
:
as a symbol in a#define
, so you'd have to use some other means of replacing them, at which point, you should probably use something like @raxvan's answer