Equivalent to Lua "and/or" in C++?

c++, lua

Solution

There's the ternary operator. It has funny precedence, so it's good practice to always parenthesize it.

bool foo = ( a ? b : ( c ? d : e ) )

Note that this only works if `b`, `d`, and `e` can reduce to the same type. If `a` is a `double`, `d` is a `float` and `e` is an `int`, your result will always be cast to a `double`.

Problem

In Lua, you can do this: ``` foo = a and b or c and d or e ``` Which is equivalent to (at least I am pretty sure it is equivalent to): ``` local foo = nil if a then foo = b elseif c then foo = d else foo = e end ``` Is there anything equivalent or similar to this in C++?

Original source