DMD 1.014 release
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Tue May 1 04:55:22 PDT 2007
Bruno Medeiros wrote:
> Walter Bright wrote:
>> Sports associative array literals, and struct literals. This enables
>> compile time function execution to work with symbol tables (AA's) and
>> user defined types.
>>
>> http://www.digitalmars.com/d/changelog.html
>>
>> http://ftp.digitalmars.com/dmd.1.014.zip
>
> "If any of the keys or values in the KeyValuePairs are an
> ExpressionTuple, then the elements of the ExpressionTuple are inserted
> as arguments in place of the tuple. "
>
> Can you give an example of that? I was thinking of something like:
> int[char[]] f;
> f = [ Tuple!(["one"[]:1, "two":2]) ];
> but it didn't work.
I hadn't tried yet, but I just did:
---
import std.stdio;
template Tuple(Ts...) { alias Ts Tuple; }
void main() {
// This is pretty cool:
writefln([Tuple!(4,5,6) : Tuple!(-1,-2,-3)]);
// outputs: [4:-1,5:-2,6:-3]
// But it doesn't seem to care if the numbers of keys and values
// go out-of-sync: (I wonder if this is a bug)
writefln([1 : Tuple!(100, 200, 300), 111 : 222, Tuple!(2,3,4) : -400]);
// outputs: [1:100,2:300,3:222,4:-400,111:200]
// And the number of keys must match the number of values
//writefln([1 : Tuple!(1,2)]);
// Compile-time error:
// "Error: number of keys is 1, must match number of values 2"
}
---
Like it says in the comment, I wonder if the behavior of the second one
is a bug...
More information about the Digitalmars-d-announce
mailing list