Comment #0 by qs.il.paperinik — 2021-04-06T16:15:16Z
Allow
expr ? type1 : type2
where a type is expected.
Type:
+ ConditionalType
TypeCtors[opt] BasicType TypeSuffixes[opt]
+ ConditionalType:
+ OrOrExpression ? BasicType : ConditionalType
Some small conditions don't warrant 4 (or 8) LoC for defining an alias.
static if (bits > 32)
{
alias Word = ulong;
}
else
{
alias Word = uint;
}
versus
alias Word = bits > 32 ? ulong : uint;
Another win is you can use the conditional type without having to define an alias.
Comment #1 by qs.il.paperinik — 2021-04-06T16:39:02Z
Obvious semantics:
ConditionalType. The OrOrExpression is evaluated at compile-time. If it evaluates to `true`, the Type expression results to the given BasicType, if it evaluates to `false`, it results to the ConditionalType. If the evaluation fails, it is an error.
Comment #2 by robert.schadek — 2024-12-13T19:15:49Z