array literal element types
Steven Schveighoffer
schveiguy at yahoo.com
Fri Nov 13 04:34:14 PST 2009
On Thu, 12 Nov 2009 20:16:40 -0500, Robert Jacques <sandford at jhu.edu>
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;
>
How about if a cast is sticky? That is, the last detected cast inside an
array literal is applied to subsequent elements that do not have a cast:
[cast(float)1.0, 2.5, 5.6, 0.8]; // equivalent to [1.0f, 2.5f, 5.6f, 0.8f]
=> float[]
[cast(float)1.0, 2.5, cast(double)5.6, 0.8]; // equivalent to [1.0f, 2.5f,
5.6, 0.8] => double[]
-Steve
More information about the Digitalmars-d
mailing list