Automatic typing

Walter Bright newshound2 at digitalmars.com
Fri Jun 28 18:36:14 PDT 2013


On 6/28/2013 4:42 PM, Timon Gehr wrote:
> On 06/29/2013 12:29 AM, Walter Bright wrote:
>> I don't see a compelling use case for this proposal, or even any use
>> case. There'd have to be some serious advantage to it to justify its
>> complexity.
>
> Eg:
>
> auto a;

     typeof(cache[x]) a;   // (1)

> if(x in cache) a=cache[x];
> else cache[x]=a=new AnnoyingToSpellOutBeforeTheIf!"!"();

Or:

   auto a = (x in cache) ? cache[x] : (cache[x]=new 
AnnoyingToSpellOutBeforeTheIf!"!"());   // (2)

>
> Using the type of the lexically first assignment would often be good enough,
> where reading the variable is disallowed prior to this first assignment.

So far, the use case is not compelling.

> A little better (and still decidable) would be using the common type of all
> branches' first assignments not preceded by a read.

(1) handles that.

Not every workaround needs a language feature.


More information about the Digitalmars-d mailing list