array literal element types
Don
nospam at nospam.com
Fri Nov 13 00:03:00 PST 2009
Robert Jacques wrote:
> On Thu, 12 Nov 2009 21:03:04 -0500, Chad J
> <chadjoan at __spam.is.bad__gmail.com> wrote:
>
>> Robert Jacques wrote:
>>> On Thu, 12 Nov 2009 16:42:45 -0500, Walter Bright
>>> <newshound1 at digitalmars.com> wrote:
>>>
>>>> Currently, the type is determined by the type of the first element and
>>>> the rest are implicitly cast to it.
>>>>
>>>> I propose changing it to being the type produced by applying the ?:
>>>> logic repeatedly to all the elements.
>>>
>>> Given how numeric literals currently work:
>>> vote--
>>>
>>> for example currently:
>>> float[] = [1.0f, 2.5, 5.6, 0.8].dup;
>>>
>>> under the proposal
>>> float[] = [1.0f, 2.5f, 5.6f, 0.8f].dup;
>>>
>>
>> Wait... just to be clear, is this because [1.0f, 2.5, 5.6, 0.8] would,
>> under the proposed, become a double[4] and thus not be duppable to
>> float[]?
>
> Yes. This also applies to static array initialization and other types
> (byte, short, etc.)
If array literals were immutable <g>, the implicit casting rules could
apply to them, so that the current code would continue to work.
More information about the Digitalmars-d
mailing list