374
|
1 // $HeadURL$
|
|
2 // $Date$
|
|
3 // $Author$
|
|
4
|
|
5 module dstress.run.foreach_10;
|
0
|
6
|
|
7 class MyArray{
|
|
8 double[] array;
|
|
9
|
|
10 this(){
|
|
11 array=new double[3];
|
|
12 array[0]=0.0;
|
|
13 array[1]=4.0;
|
|
14 array[2]=8.0;
|
|
15 }
|
|
16
|
1535
|
17 int opApply(int delegate(ref double) dg){
|
0
|
18 double result;
|
|
19 for(int i=0; i<array.length; i++){
|
|
20 result = dg(array[i]);
|
|
21 if(result){
|
|
22 return i;
|
|
23 }
|
|
24 }
|
|
25 return array.length;
|
|
26 }
|
|
27 }
|
|
28 int main(){
|
|
29 MyArray array=new MyArray();
|
|
30 double test=0.0;
|
|
31 assert(test==0.0);
|
|
32 foreach(double value; array){
|
|
33 test+=value;
|
|
34 }
|
|
35 assert(test==12.0);
|
|
36 return 0;
|
1
|
37 }
|