Array literals MUST be immutable.
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Thu Feb 18 06:15:31 PST 2010
Steven Schveighoffer wrote:
> On Thu, 18 Feb 2010 08:00:55 -0500, Don <nospam at nospam.com> wrote:
>
>> Including the library implementation:
>>
>> T[] toArray(T)(T[] values...)
>> {
>> return values.dup;
>> }
>>
>> int[] array = toArray(x,y,z);
>>
>> Mutable array literals achieve almost nothing.
>>
>
> I don't think this will work:
>
> toArray(1, 2L, 3.0)
>
> I'm not saying that this is a reason not to consider the change, but it
> does note a difference. You can always simply do toArray!double(...) to
> get around the limitation.
>
> -Steve
import std.traits: CommonType;
CommonType!(T)[] toArray(T...)(T elements) { ... }
-Lars
More information about the Digitalmars-d
mailing list