Feature request - type inference for new

Yossarian xtauer01 at stud.fit.vutbr.cz
Mon Jun 16 17:09:08 PDT 2008


Dne Mon, 16 Jun 2008 21:33:58 +0200 Jason House  
<jason.james.house at gmail.com> napsal/-a:

> 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);
>


I'm not sure, if this suggestion doesn't break the language context-less  
grammar.
imagine:

auto c = new auto ();

.. what now? This is nonsense, but gramatically correct.

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



-- 
Tato zpráva byla vytvořena převratným poštovním klientem Opery:  
http://www.opera.com/mail/



More information about the Digitalmars-d mailing list