What's the constexpr-if equivalent to `condition ? x : y`? As far as I know we only have `[&] { if constexpr (condition) return x; else return y; }()`. I hate it.
What's the constexpr-if equivalent to `condition ? x : y`? As far as I know we only have `[&] { if constexpr (condition) return x; else return y; }()`. I hate it.
@mkretz
Correct.
AFAIK, nobody ever proposed an equivalent.
What would your envisioned semantic look like?
* no search for a 'common type'?
* one of the two 'sub-expressions' is 'discarded', like in https://eel.is/c++draft/stmt.if#2 ?
@mkretz
No, similar to a templated function like this
template <typename T>
auto first_in(const T &x) {
if constexpr (some_cond_based_on_T)
return x[0];
else
return x;
}
@mkretz
Propose "do expressions" 🤭
Oh wait, Barry already did that AFAIK. They are an important building block for 'pattern matching' as proposed. Otherwise it would become as annoying as in your use-case.
Oh shoot. 💩
OTOH, this would open another venue for Nico to give highly oninionated talks 😂