Small suggestion for default constructors
TheZipCreator
thezipcreator at protonmail.com
Tue Jan 17 13:12:46 UTC 2023
On Tuesday, 17 January 2023 at 03:12:09 UTC, Adam D Ruppe wrote:
> On Tuesday, 17 January 2023 at 02:45:30 UTC, TheZipCreator
> wrote:
>> default this(float x, float y, float z);
>
> Try this out:
>
> class Foo {
> int x;
> int y;
> int z;
>
> // one little function
> this(typeof(this.tupleof) t) {
> this.tupleof = t;
> }
> }
>
> void main() {
> auto foo = new Foo(1, 2, 3);
> assert(foo.x == 1);
> assert(foo.y == 2);
> assert(foo.z == 3);
> }
ooh, that's an interesting usage of `tupleof`. I didn't even know
it could be used as an lvalue. This is a bit unclear if you don't
know the internals of D though. also, this wouldn't work if you
just want to initialize one or two values and not all of them,
but still could be useful.
More information about the Digitalmars-d
mailing list