pred_switch manual example
Andy Balba
pwplus7 at gmail.com
Wed Jul 29 21:46:04 UTC 2020
The following example taken from
https://dlang.org/library/std/algorithm/comparison/pred_switch.html
doesn't compile under gdc...Is there a way to fix it ?
int factorial(int n)
{
return n.predSwitch!"a <= b"(
-1, {throw new Exception("Can not calculate n! for n <
0");}(),
0, 1, // 0! = 1
n * factorial(n - 1) // n! = n * (n - 1)! for n >= 0
);
}
writeln(factorial(3));
The gdc compiler error is
error: no property 'predSwitch' for type 'int'
return n.predSwitch!"a <= b"(
More information about the Digitalmars-d
mailing list