title: Compile Time Code Generation in D
body: <p>I'm currently learning D, and one of the things I've wondered about is whether D has a way of duplicating the code generation capabilities of JVM languages.</p>
  
  <p>Here's a scenario:
  I have an object, and I want to generate a string based on that object that gives it's name and all its fields. In Java/Scala, I <em>could</em> just use reflection, but suppose speed is an issue. I could use a bytecode generation library to dynamically generate and compile a class that does this without reflection. The implementation would break down to iterating through the object's fields and getting it's name through recursion, and using that information to dynamically generate Java (or bytecode) that accesses the fields directly.</p>
  
  <p>If you don't like that scenario because it's weak and/or unrealistic, another one that might be more realistic is optimized object serialization.</p>
  
  <p>I've seen examples where D's compile time evaluation and/or template metaprogramming is used for things like precalculating the fibonacci sequence at compile time and other recursive algorithms, but is there a way of doing things like this with just the language and a compiler, or would you need to develop a separate code-generator and run it before the compiler to get this sort of functionality?</p>