macros: type save, or what?

renoX renosky at free.fr
Wed Sep 12 12:48:49 PDT 2007


0ffh a écrit :
> As to the matter of type save macros:

I don't know if typesafe macros will be used that much though, 
duck-typing (ie if it compiles then it's good) seems enough most of the 
time, have you a specific example where typesafe macros are useful?

Regards,
renoX

> Using some imaginary macro sytax (as I don't know the real one),
> but with all confidence that this will work with D macros.
> 
> macro inc(a)
> // increment an integer
> {
>   static if (typeof(a).stringof=="int")
>   {
>     ++a;
>   }
>   else
>   {
>     // raise compile time error
>     static assert(false,"inc wanna int!!11!");
>   }
> }
> 
> There might even be a more elegant way, but what teh heck... :)
> 
> Regards, Frank



More information about the Digitalmars-d mailing list