Would this be a useful construct to add to D? auto for constructor call.

Chris Katko ckatko at gmail.com
Tue Jan 23 06:05:28 UTC 2024


```D
class dataGridLayerView{
    int t;
    this(int _t){
       t = _t;
       }
    }

class myClass{
    dataGridLayerView dataGrid;

    this()
       {
       dataGrid = new auto(15); // <--- new
       // instead of
       dataGrid = new dataGridLayerView(15);
       }
    }
```

Because it seems, conceptually, the compiler should know all the 
details required here to simply insert the right constructor 
name. Basically just the reverse of:

```D
auto t = sqrt(15);
```

So intuitively it makes sense to me.

It might even be possible to write a mixin to do this, I'm not 
sure.

I'm no D wizard, but I don't see any obvious name or lexing 
conflicts/ambiguity.

Cheers,
--Chris


More information about the Digitalmars-d-announce mailing list