Meta-programming - examples
Kirk McDonald
kirklin.mcdonald at gmail.com
Sun Feb 11 03:40:26 PST 2007
janderson wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> janderson wrote:
>>>
>>> ect...
>>>
>>>
>>> ");
>>> //Note that there should be a way to disable CheckCode in the general
>>> case to save compile time
>>
>> I guess this is an obvious:
>>
>> mixin(CheckCode(import "program.d"));
>
> Now that I think about it, what about:
>
> version (CheckCode) { mixin(checkCode(__FILE__)) }
>
> //Rest of file
> ...
>
> checkCode would probably make use of static asserts. Is it possible to
> write a message to compiler output? That would be a handy
> static-compilation tool.
>
There are two ways:
pragma(msg, "Compile-time output.");
And:
static assert(false, "Making the compiler die, now...");
> Or maybe it could be in the unit-tests. Actually you can probably do
> that in unit tests already even without mixin Expressions.
>
> -Joel
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list