CTFE vs. traditional metaprogramming

Don nospam at nospam.com
Sat Oct 10 01:26:11 PDT 2009


Jarrett Billingsley wrote:
> On Fri, Oct 9, 2009 at 3:49 PM, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>> Thanks!
>>
>>
>> I plan to add more text at the end of the chapter that discusses the
>> opportunities of CTFE. Walter revealed to me that CTFE, particularly now
>> after it's been improved by leaps and bounds by Don and by Walter himself,
>> could obviate a lot of the traditional metaprogramming techniques developed
>> for C++.
>>
>> One question that bugs me is, where do you draw the line? Say there's a
>> metaprogramming problem at hand. How to decide on solving it with CTFE vs.
>> solving it with templates? It would be great to have a simple guideline that
>> puts in contrast the pluses and minuses of the two approaches.
>>
>> It is quite possible that templates get relegated to parameterized functions
>> and types, whereas all heavy lifting in metaprogramming should be carried
>> with CTFE.
> 
> God, I wish we had a real forum with table capabilities. I can't even
> rely on monospaced fonts..
> 
> Where templates win at metaprogramming:
> 
> Templates have pattern-matching capabilities for picking apart types.
> CTFE is forced to reimplement part of the D lexer/parser to do so (and
> combined with buggy/incompletely specified .stringof, you can't really
> depend on your parsing to work right).

CTFE doesn't mean "string mixins using CTFE".
It just means CTFE. (BTW you can do string mixins with templates only, 
no CTFE, if you are completely insane).



More information about the Digitalmars-d mailing list