Feature request - type inference for new

Koroskin Denis 2korden at gmail.com
Mon Jun 16 10:47:25 PDT 2008


On Mon, 16 Jun 2008 21:23:19 +0400, Janice Caron <caron800 at googlemail.com>  
wrote:

> I've been quiet for a while. (Actually, I've been offline for a
> while). So, I thought I'd better come back with a new feature request!
> :-) Type inference for new. Here's an example:
>
>     class C(T)
>     {
>         Some!(Funky!(Class!(T))) funky;
>
>         this()
>         {
>             funky = new;
>         }
>     }
>
> The type of funky is in the declaration, so why repeat it?
>
> Another example...
>
>     class AnotherClassWithAVeryLongName
>     {
>         int x,y;
>
>         this(int x, int y) { this.x = x; this.y = y; }
>     }
>
>     void foo(int a, int b)
>     {
>         AnotherClassWithAVeryLongName c;
>
>         if (a < b) c = new(a,b);
>         else c = new(b,a);
>     }
>
> Again, no need to repeat the type of c, because it's in the
> declaration (this time a local declaration).
>
> This will only work for assignments, because D doesn't overload on
> return type. But still - I'm all for anything that saves typing.

Well, this one doesn't improve readability. I wouldn't use that,  
especially if there is a bulk of code between

AnotherClassWithAVeryLongName c;

and

c = new(a,b);



More information about the Digitalmars-d mailing list