comparison run/foreach_10.d @ 0:3269e4627918

init dstress
author svnowner
date Sat, 25 Sep 2004 22:33:30 +0000
parents
children 3414705c41ac
comparison
equal deleted inserted replaced
-1:000000000000 0:3269e4627918
1 // $Header: /home/th/Dokumente/Entwicklung/MEIN_CVS/MiniD/src/run/foreach_10.d,v 1.1 2004/09/21 21:04:47 th Exp $
2
3 class MyArray{
4 double[] array;
5
6 this(){
7 array=new double[3];
8 array[0]=0.0;
9 array[1]=4.0;
10 array[2]=8.0;
11 }
12
13 int opApply(int delegate(inout double) dg){
14 double result;
15 for(int i=0; i<array.length; i++){
16 result = dg(array[i]);
17 if(result){
18 return i;
19 }
20 }
21 return array.length;
22 }
23 }
24 int main(){
25 MyArray array=new MyArray();
26 double test=0.0;
27 assert(test==0.0);
28 foreach(double value; array){
29 test+=value;
30 }
31 assert(test==12.0);
32 return 0;
33 }