My programming and teaching blog

Intro to D metaprogramming - Creating a JSON serialiser

Created 31/10/2019 | Updated 07/05/2020 Status: finished

A series of blog posts that cover how to create a basic JSON serialiser in D, while teaching several different aspects of D's metaprogramming, such as templates; template arguments; function contracts; static if; static foreach; mixins; and more.

  1. Serialising basic D types
  2. Serialising basic D types - Alternative function layout
  3. Serialising structs
  4. Serialising enums and classes
  5. Serialising arrays
  6. Using UDAs for customisation
  7. Mixin template to automate static deserialise

Metaprogramming in D

Created 01/05/2021 | Updated 01/05/2021 Status: WIP

D boasts one of the strongest, most flexible array of metaprogramming features amongst most existing languages, which allows it the ability to perform use-cases such as automating boilerplate without the need of external tooling; generating compiler optimised D code from a regex at compile-time; and running functions at compile-time to generate values/more code. All done using the language's built-in features with little compromise.

  1. Text templates that can execute code at compile-time