Is there a way to make a function parameter accept only values that can be checked at compile time?
Steven Schveighoffer
schveiguy at gmail.com
Tue Dec 28 22:06:50 UTC 2021
On 12/28/21 4:19 PM, rempas wrote:
Here:
> ```
> extern (C) void main() {
> void print_num(int mul)(int num) {
> static if (is(mul == ten)) {
> printf("%d\n", num * 10);
> } else static if (is(mul == three)) {
> printf("%d\n", num * 3);
> } else {
> printf("%d\n", num);
> }
> }
>
> int multi = 211;
> print_num!3(10); // Ok, accept this
> print_num!multi(10); // Error, do not accept this
> }
> ```
-Steve
More information about the Digitalmars-d-learn
mailing list