Meta-programming - examples

janderson askme at me.com
Sat Feb 10 20:58:33 PST 2007


janderson wrote:
> 
> Simplify saving/loading of arbitrary structures.
> 
> //Only write this once.  Things are re-ordered for best fit in memory, 
> localization ect...
> mixin(Serailzable("Ship",
> "
>     struct Part
>     {
>         float firePower;
>         char[] Model;
>     }
> 
>     struct Ship
>     {
>         bool Friendly;
>         Part Parts[];
>     }
> ");
> 
> ... Later
> 

I wrote this up pretty fast, you probably got the point.  However:

 > Load("Ship", "Ship.asset");
 >

would probably look more like:

Ship ship;
Load(ship, "Ship.asset");
...
Save(ship, "Ship.asset");

-Joel



More information about the Digitalmars-d mailing list