Static ternary if
Cauterite via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 25 15:27:11 PDT 2016
On Monday, 25 July 2016 at 02:15:12 UTC, Gorge Jingale wrote:
> Is there a static ternary if?
>
> (A == B) ? C : D;
>
> for compile type that works like static if.
You can pretty easily make your own;
template staticIf(bool cond, alias a, alias b) {
static if (cond) {
alias staticIf = a;
} else {
alias staticIf = b;
};
};
The drawback is that there's no 'short-circuiting'; a and b are
both evaluated.
More information about the Digitalmars-d-learn
mailing list