Dne 3.3.2016 v 07:12 Shriramana Sharma via Digitalmars-d-learn napsal(a):
Hello. I have a function I want to make CTFE-able as a template.
string ta(string s) { return s ~ "1"; }
template ta(string s) { enum ta = ta(s); }
void main() { string s = ta!"s"; }
Compiling the above I get the errors:
<src>(2): Error: forward reference of variable ta
<src>(3): Error: template instance <src>.ta!"s" error instantiating
Please clarify what I am doing wrong? Thanks!
You cant use same name for both:
import std.stdio;
auto ta2(string s) { return s ~ "1"; }
enum ta(string s) = ta2(s);
void main() {
string s = ta!"s";
writeln(s);
}