array of elements of various sybtypes
spir
denis.spir at gmail.com
Thu Jan 27 05:26:20 PST 2011
On 01/27/2011 03:59 AM, Steven Schveighoffer wrote:
> On Wed, 26 Jan 2011 18:28:12 -0500, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>
>
>> I believe that it's supposed to take the common type of t1 and t2 and make the
>> result an array of that type. So, assuming that the common type is T0, then it
>> should work. However, it's not currently implemented that way. You could always
>> create a bug report so that it doesn't get lost (assuming that no such report
>> already exists).
>>
>
> Object could also be the common type.
Very true.
> When there exists multiple possibilities,
> and none of the possibilities are types being passed to the array literal, I
> think it just gives up (D usually gives up in the face of ambiguity, instead of
> possibly making the wrong decision).
That's OK.
> But the problem here appears that there is no way to *force* it to make the
> right decision.
Yes, that's what I meant in another post. We should have a way to hint the
compiler about intended common type /before/ it even tries to contruct an
initial array value (which else fails). But I have no idea how; should be a
syntactic trick. There is no "literal-typing" pattern in D, instead the
compiler always performs type induction from the form.
> I'd like to see cast(T0[])[...] work, I think that should solve the problem.
See "/before/" above (cast applies on already constructed value).
The only alternative is, I guess, when the compiler initially fails to find a
common type, to have it look for a hint by interpreting the target; then
explicit array var typing would work:
T0[] ts = [t1, t2];
But it seems to me rather complicated. (There are many different situations in
which literals may appear).
> -Steve
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d-learn
mailing list