On Fri, 23 Sep 2011 14:47:32 -0400, Gor F. Gyolchanyan
<gor.f.gyolchan...@gmail.com> wrote:
Of course, if the entire D gets CTFE-able, the __ctfe will be completely
useless.
But i can't see that coming for a long time.
Well, anywhere that it makes sense, it should be CTFE-able.
For example to!string(int) should be CTFE-able, as well as to!int(string)
I think a really cool CTFE feature would be if sort could be used in
compile time. Imagine writing a lookup table in whatever order you want,
then just using:
enum lookupTable = sorted(lookupData);
I can think of a few places that would have been useful in my past.
Places where __ctfe is useful are functions that depend on opaque runtime
functions. Then you can write alternatives. Again, I'll refer you to
std.array.Appender.
Most of the major programming
problems are best solved with classes and that's where CTFE stops.
I'm not sure everybody agrees on that. Classes are good for certain
things, and horrible for others.
About templates:
void unpackIntoFunction(alias arrayOfVariants, alias func)()
{
// you can't generate the necessary mixin strings right here, because
it won't
be compile-time.
// you need to create a separate function, that returns the required
string to
be mixed in.
mixin(whatIJustGenerated);
}
enum + static if signifies compile time. If you want to use the
compile-time constructs, you can build it at compile-time. Otherwise, you
can either use eponymous templates (functional style) or CTFE-able
functions (imperative style).
A more complete example will allow better explanation.
-Steve