The Expressiveness of D

Jesse Phillips jessekphillips+D at gmail.com
Tue Nov 2 07:26:11 PDT 2010


Torarin Wrote:

> > // these don't work - why?
> > //  auto b = [new B, new C];
> > //  auto c = { return [1: new B,2: new C]; };
> 
> That seems to be just a matter of improving the compiler to make it
> find the common type. I don't think there's anything in the language
> stopping that from working.

I don't recall why it doesn't find the common type. But what it does do is use the last element to deduce the type, so there are two ways to make this work.

auto b = [new B, cast(A) new C];
auto b = [new B, new C, new A];

What I don't really like is that it can't be fixed with:

A[] b = [new B, new C];


More information about the Digitalmars-d mailing list