Is there a way to make a function parameter accept only values that can be checked at compile time?
rempas
rempas at tutanota.com
Tue Dec 28 21:19:29 UTC 2021
I would like to know if that's possible. Actually I would like to
do something like the following:
```
extern (C) void main() {
void print_num(int num, comp_time_type int mul) {
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(10, 3); // Ok, accept this
print_num(10, multi); // Error, do not accept this
}
```
So I want to have "mul" only accept values that can be calculate
at compile time so I can use it with things like "static if". Is
this possible?
More information about the Digitalmars-d-learn
mailing list