array of elements of various sybtypes

spir denis.spir at gmail.com
Thu Jan 27 04:49:06 PST 2011


On 01/27/2011 03:54 AM, Steven Schveighoffer wrote:
> On Wed, 26 Jan 2011 18:33:45 -0500, spir <denis.spir at gmail.com> wrote:
>
>> On 01/26/2011 07:23 PM, Steven Schveighoffer wrote:
>>> On Wed, 26 Jan 2011 12:27:37 -0500, spir <denis.spir at gmail.com> wrote:
>>>

>>> auto ts = cast(T0[])[t1, t2];
>>
>> Nope, refused for the same reason (tried to construct [t1,t2] before casting
>> it).
>
> Hm.. maybe that only works on array literals with all literal elements. I
> expected the cast to affect the type the compiler is expecting.
>
> For example, this works:
>
> cast(ubyte[])[1,2]; // without cast typed as int[]

Yes, but with [1,2] the compiler has no difficulty to create the initial array 
in the first place ;-)
With [t1,t2], it fails in that very first task, before even having a chance to 
redefine the whole array's type.

> I believe there should be a way to tell the array literal "this is the type you
> should be."

Yes, exactly; I superficially thought specifying it explicitely on the left of 
'=' would do the job, just like you cast(T[]). But Jonathan is right in saying 
in any case the array literal must be interpratable first.

>  If that's not possible, then it needs to be added. If it's expected
> the cast should work, then I'd file a bug against it.

Yop, but I don't even see the shadow of a solution ;-)

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d-learn mailing list