Feature request - type inference for new

Jason House jason.james.house at gmail.com
Mon Jun 16 12:33:58 PDT 2008


I'd prefer using the auto keyword as a replacement for the missing type...  ie. the following candidate syntaxes:
  funky = new auto;
  funky = new auto();
  c = new auto(a,b);
  c = new auto(b,a);

Janice Caron 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.




More information about the Digitalmars-d mailing list