resizeable arrays: T[new]

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Jun 8 16:56:48 PDT 2007


"Walter Bright" <newshound1 at digitalmars.com> wrote in message >
> Because static arrays can be implicitly cast to unresizable arrays, but 
> not vice versa.

Why would you need it to implicitly cast to a static array?  So you can 
initialize things like "char[4] = "abcd";" ?

>
> I don't know what you mean.

// cannot implicitly convert expression (["hi","bye"]) of type char[][2] to 
char
// auto a = ["hi", "bye"];

// works
auto a = ["hi"[], "bye"];

int[char[]] aa;

// cannot implicitly convert expression ("bye") of type char[3] to char[2]
//aa = ["hi":1, "bye":2];

// works
aa = ["hi"[]:1, "bye":2];

typeof(T[0]) foo(T...)()
{
    return T[0];
}

// Error: functions cannot return static array char[2]
//foo!("hi")();

// works
foo!("hi"[])();

Templates also have to deal with static array types in completely different 
ways, since they can't be returned and their .init is not the same type as 
them. 





More information about the Digitalmars-d-announce mailing list