Re: Generating custom toString for structs

2024-01-11 Thread cc via Digitalmars-d-learn
On Thursday, 11 January 2024 at 12:45:45 UTC, cc wrote: I don't use the delegate version personally, but if that's already working for you, may as well stick with it. In retrospect, that delegate version is probably quite a bit better.

Re: Generating custom toString for structs

2024-01-11 Thread cc via Digitalmars-d-learn
On Sunday, 7 January 2024 at 09:49:36 UTC, Renato wrote: Hi, I wanted to customize the toString implementation for my structs. So I wrote a mixin for doing that: Alternative format similar to what you already have: ```d import std.format; mixin template ToStringMixin() { void

Re: Generating custom toString for structs

2024-01-07 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 7 January 2024 at 09:49:36 UTC, Renato wrote: Is the above a "good" way to do this? It looks ok to me. There are some minor changes I would make, like using `typeof(this)` instead of `S` to refer to the type of the struct you're mixing it into, but the overall approach is fine.