mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-10-15 21:47:01 +02:00
[svn r113] Added initial support for associative arrays (AAs).
Fixed some problems with the string runtime support functions. Fixed initialization of array of structs. Fixed slice assignment where LHS is slice but RHS is dynamic array. Fixed problems with result of assignment expressions. Fixed foreach problems with key type mismatches.
This commit is contained in:
@@ -3,4 +3,13 @@ module aa1;
|
||||
void main()
|
||||
{
|
||||
int[int] aai;
|
||||
assert(aai is null);
|
||||
aai[0] = 52;
|
||||
assert(aai !is null);
|
||||
int i = aai[0];
|
||||
assert(i == 52);
|
||||
aai[32] = 123;
|
||||
int j = aai[32];
|
||||
assert(i == 52);
|
||||
assert(j == 123);
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
module aa2;
|
||||
|
||||
void main()
|
||||
{
|
||||
long[float] aa;
|
||||
long* p = 2.0f in aa;
|
||||
assert(!p);
|
||||
aa[4f] = 23;
|
||||
p = 4f in aa;
|
||||
assert(p);
|
||||
assert(*p == 23);
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
module aa3;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[string] aa;
|
||||
{aa["hello"] = 1;}
|
||||
{int* p = "" in aa;}
|
||||
aa[" worl"] = 2;
|
||||
aa["d"] = 3;
|
||||
aa["thisisgreat"] = 10;
|
||||
int sum;
|
||||
string cat;
|
||||
{
|
||||
foreach(k,v;aa)
|
||||
{
|
||||
printf("int[%.*s] = %d\n", k.length, k.ptr, v);
|
||||
sum += v;
|
||||
cat ~= k;
|
||||
}
|
||||
}
|
||||
assert(sum == 16);
|
||||
printf("cat = %.*s\n", cat.length, cat.ptr);
|
||||
assert(cat.length == 22);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
module aa4;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[int] aa;
|
||||
aa = addkey(aa,42,12);
|
||||
int* p = haskey(aa,42);
|
||||
assert(p && *p == 12);
|
||||
}
|
||||
|
||||
int[int] addkey(int[int] aa, int key, int val)
|
||||
{
|
||||
aa[key] = val;
|
||||
return aa;
|
||||
}
|
||||
|
||||
int* haskey(int[int] aa, int key)
|
||||
{
|
||||
return key in aa;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
module aa5;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[int] aa;
|
||||
aa[42] = 1;
|
||||
int i = aa[42];
|
||||
assert(i == 1);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
module arrays14;
|
||||
|
||||
void main()
|
||||
{
|
||||
auto s = "hello world";
|
||||
auto d = s.dup;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
module typeinfo13;
|
||||
|
||||
void main()
|
||||
{
|
||||
float[long] aa;
|
||||
auto ti = typeid(typeof(aa));
|
||||
assert(ti.toString() == "float[long]");
|
||||
assert(ti.next() is typeid(float));
|
||||
assert(ti.tsize() == size_t.sizeof);
|
||||
auto aati = cast(TypeInfo_AssociativeArray)ti;
|
||||
assert(aati.value is typeid(float));
|
||||
assert(aati.key is typeid(long));
|
||||
}
|
||||
Reference in New Issue
Block a user