DMD 0.170 release
Bill Baxter
dnewsgroup at billbaxter.com
Tue Oct 17 18:43:47 PDT 2006
Bill Baxter wrote:
> Is there any reason for not allowing a function to be used too?
> Then you could also use a closure as the thing that does the iteration:
Ok, I just realized that "delegate" can also be pointer to a non-static
nested function... Duh. So my question should have been -- why doesn't
this work?
int delegate(int delegate(inout ElemT))
reversed(AggregateT,ElemT)(AggregateT array)
{
int _innerFunc(int delegate(inout ElemT) loopBody)
{
int done = 0;
for (int i = array.length-1; i >=0; i--)
{
done = loopBody(array[i]);
if (done)
break;
}
return done;
}
return &_innerFunc;
}
...
foreach(real r; reversed!(real[],real)(areal))
{...}
Compiles but gives:
"Error: Access Violation"
I'm not totally clear on how pointers/objects are handled in D. It
looks the call to reversed() is maybe creating a copy of the data? If I
put in printfs the pointer value is different from that of the original
int[].
--bb
More information about the Digitalmars-d-announce
mailing list