On Wednesday, 14 July 2021 at 23:16:05 UTC, Dylan Graham wrote:
[DUB](https://code.dlang.org/packages/record)
[Github](https://github.com/hmmdyl/record)

record now has support for custom default initialisers. Example:

```D
import drecord;

alias DefaultRecord = record!(
// The third parameter is a lambda which provides default initialisation
    get!(int, "x", () => 4), // x is set to 4 by default
get_set(Object, "o", () => new Object) // o is set to a new Object by default
);

auto r = new DefaultRecord; // run the default initialisers
writeln(r); // {x = 4, o = object.Object}

auto q = DefaultRecord.create!"x"(9); // run default initialisers, then set x to 9
writeln(r); // {x = 9, o = object.Object}
```

Reply via email to