mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-10-12 06:07:00 +02:00
[svn r38] * resizing dynamic arrays support
* throw is replaced with assert(0) * catch is ignored * better foreach support * various bugfixes
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
module arrays3;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[] arr;
|
||||
{arr = new int[25];}
|
||||
{assert(arr.length == 25);}
|
||||
{arr.length = arr.length + 5;}
|
||||
{assert(arr.length == 30);}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
module bug7;
|
||||
|
||||
class love { }
|
||||
void bug() {
|
||||
love[] child;
|
||||
child.length=1;
|
||||
assert(child[0] is null);
|
||||
child[0]=null;
|
||||
assert(child[0] is null);
|
||||
}
|
||||
void main()
|
||||
{
|
||||
bug();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
module foreach2;
|
||||
|
||||
void main()
|
||||
{
|
||||
static arr = [1.0, 2.0, 4.0, 8.0, 16.0];
|
||||
foreach(i,v; arr)
|
||||
{
|
||||
printf("arr[%d] = %f\n", i, v);
|
||||
}
|
||||
printf("-------------------------------\n");
|
||||
foreach_reverse(i,v; arr)
|
||||
{
|
||||
printf("arr[%d] = %f\n", i, v);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
module foreach3;
|
||||
|
||||
void main()
|
||||
{
|
||||
static str = ['h','e','l','l','o'];
|
||||
foreach(i,v; str) {
|
||||
printf("%c",v);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
foreach(i,v; str) {
|
||||
v++;
|
||||
}
|
||||
|
||||
foreach(i,v; str) {
|
||||
printf("%c",v);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
module memory1;
|
||||
|
||||
void main()
|
||||
{
|
||||
auto a = new int[16];
|
||||
{printf("array.length = %u\n", a.length);}
|
||||
{a.length = a.length + 1;}
|
||||
{printf("array.length = %u\n", a.length);}
|
||||
{assert(a.length == 17);}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
module throw1;
|
||||
|
||||
extern(C) int rand();
|
||||
|
||||
class C
|
||||
{
|
||||
}
|
||||
|
||||
void func()
|
||||
{
|
||||
if (rand() & 1)
|
||||
throw new C;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
func();
|
||||
}
|
||||
catch(Object)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user