Discussion Thread: DIP 1043--Shortened Method Syntax--Final Review
Nick Treleaven
nick at geany.org
Fri Jun 17 13:17:37 UTC 2022
On Thursday, 16 June 2022 at 18:56:57 UTC, Paul Backus wrote:
> class Point
> {
> Color rgba;
> int x, y;
> bool hidden;
>
> mixin(defaultClassConstructor);
> }
It could also allow skipping some fields and support custom
initialization of those fields using a function literal:
```d
// declare `this(rgba, x, y)`, no `hidden` parameter
mixin defaultClassCtor!("!hidden", { hidden = ...; });
```
The function literal would run after the default assignments.
Alternatively the parameters to use could be listed:
```d
// declare `this(rgba, x, y)`, no `hidden` parameter
mixin defaultClassCtor!(q{rgba, x, y}, { hidden = ...; });
```
It could skip private fields by default, or include them with a
flag:
```d
// include private fields
mixin defaultClassCtor!(Yes.privateFields);
```
It could support default arguments:
```d
mixin defaultClassCtor!(q{x = 0, y = 10});
```
And ddoc works for a documented template mixin declaration
containing a documented constructor.
More information about the Digitalmars-d
mailing list