Search code examples
templatesmetaprogrammingd

D Templates: Coolest Hack


What is the coolest somewhat practical metaprogramming hack you've done or seen done in the D programming language? Somewhat practical means excluding, for example, the compile-time raytracer.


Solution

  • In terms of the outright coolest, I'd have to say Kirk McDonald's PyD (and other similar bindings) as these have do to a huge amount of work in detecting and handling lots of different types, as well as complex code generation.

    That said, PyD only wins because BLADE technically uses CTFE, not templates.

    On a more personal note, D templates have gotten extensive use in a research project of mine. It's a simulation framework where modules can define their own private data types. Exposing a new user type to the framework requires a single line of code which creates an XML parser for the type as well as associated network serialisation/deserialisation code.