Would this be a useful construct to add to D? auto for constructor call.
Steven Schveighoffer
schveiguy at gmail.com
Tue Jan 23 16:01:55 UTC 2024
On Tuesday, 23 January 2024 at 11:11:00 UTC, ryuukk_ wrote:
> On Tuesday, 23 January 2024 at 06:30:08 UTC, Jonathan M Davis
> wrote:
>> That being said, I expect that it would be pretty easy to
>> write a mixin to do something like that if you really wanted
>> to. Also, if you're simply looking to not have to name the
>> type, you could do
>>
>> dataGrid = new typeof(datagrid)(15);
>>
>
> You like to turn off people before they get the chance to
> develop further, this is bad
Would you like to encourage proposals/work/effort that will
ultimately not be accepted? I don't. I would rather tell someone
no early than tell them no later. And I agree with Jonathan, zero
proposals that infer type from how they are used have been
accepted by Walter, this one probably will be no different.
To the OP, I think the value of the feature needs to be more than
just avoiding repeating the name of the type.
You also can do some library tricks (unfortunately this won't
count as construction, but probably is fine in most cases)
```d
auto create(T, Args...)(out T val, Args args)
{
static if(is(T == class))
val = new T(args);
else static if(...) // do eveyrything else.
}
...
dataGrid.create(15);
```
-Steve
More information about the Digitalmars-d-announce
mailing list