Can't read a constant value in compile time?
Adnan
contact.adnan.02 at protonmail.com
Tue Nov 20 18:54:58 UTC 2018
Godbolt: https://godbolt.org/z/SWWOu7
When I write `something!(aNumber)()` and if a number is an
immutable/enum it should be able to be read at compile time,
right? Why is this different?
auto fizzbuzz(uint N)() {
static string accumulate;
return fizzbuzz!N(accumulate);
}
auto fizzbuzz(uint N)(ref string result) if (N % 3 && N % 5) {
import std.conv : to;
result ~= N.to!string ~ "\n";
return fizzbuzz!(N - 1)(result);
}
auto fizzbuzz(uint N)(ref string result) if (!(N % 15)) {
result ~= "FizzBuzz\n";
return fizzbuzz!(N - 1)(result);
}
auto fizzbuzz(uint N)(ref string result) if (!(N % 3) && N % 5) {
result ~= "Fizz\n";
return fizzbuzz!(N - 1)(result);
}
auto fizzbuzz(uint N)(ref string result) if (!(N % 5) && N % 3) {
result ~= "Buzz\n";
return fizzbuzz!(N - 1)(result);
}
auto fizzbuzz(uint N : 0)(ref string result) {
return result;
}
void main() {
import std.stdio : writeln;
enum lmao = fizzbuzz!50();
lmao.writeln();
}
More information about the Digitalmars-d-learn
mailing list