Extend with to take multiple arguments
Bastiaan Veelo
Bastiaan at Veelo.net
Thu Jun 6 19:52:00 UTC 2019
On Thursday, 6 June 2019 at 14:36:57 UTC, 12345swordy wrote:
> On Thursday, 6 June 2019 at 07:22:38 UTC, Simen Kjærås wrote:
>> class Class {
>> int n;
>> string s;
>> }
>>
>> var exp = new Class { n = 4, s = "foo" };
>>
>> This, D doesn't do. The equivalent would be:
>>
>> class Class {
>> int n;
>> string s;
>> }
>>
>> auto exp = new Class();
>> with (exp) {
>> n = 4;
>> s = "foo";
>> }
>>
>> --
>> Simen
>
> Exactly, what I meant, thank you Simen.
>
> Alex
I see. I played with this a bit. Just for fun, there is an
alternative without “with” and without repeating the object name.
It’s not shorter nor prettier, and it’s not quite the same :-)
Anyway:
auto exp = new class Class { this() {
n = 4; s = "foo";
} };
https://run.dlang.io/is/EcC8KK
Bastiaan.
More information about the Digitalmars-d
mailing list