On Saturday, 25 February 2017 at 01:27:09 UTC, Minty Fresh wrote:
On Wednesday, 22 February 2017 at 11:18:15 UTC, Martin Tschierschke wrote:
[...]

Since structs are Plain-old Data and don't do inheritance, the best option is a template mixin.

ie.

  template mixin PrettyPrint
  {
      string toString()
      {
          // . . .
      }
  }

From there, you can mix it into any struct you want.

  struct MyStruct
  {
      mixin PrettyPrint;
  }

If you're familiar with Rails, this is similar to a Concern.

Errata on that. Should actually be declared as:

  mixin template PrettyPrint()

This is why I shouldn't make posts from my phone.

Reply via email to