Going from CTFE-land to Template-land
Bill Baxter
wbaxter at gmail.com
Tue Nov 17 05:14:55 PST 2009
Currently this doesn't work, because the CTFE function doesn't "know"
that it's running compile-time:
int templ_incr(int x)() {
return x+1;
}
int ctfe_incr(int x) {
return templ_incr!(x);
}
Seems common to write a function that you know is only intended to be
used compile-time.
But it can't compile because the compiler doesn't know you only plan
to call it at compile-time.
Is something version(__ctfe) might help with? E.g.
version(__ctfe) {
// only allow cfte_incr to be called at compile-time so it can use templates
int ctfe_incr(int x) {
return templ_incr!(x);
}
}
Or is there something more fundamental preventing CTFE funcs from
instantiating templates?
--bb
More information about the Digitalmars-d
mailing list