question about foreach, opApply, and delegates

downs default_357-line at yahoo.de
Mon Jun 8 07:01:16 PDT 2009


Jerry Quinn wrote:
> Hi, all.  I find myself a little confused about how foreach, opApply, and delegates interact according to the docs.
> 
> Foreach on an aggregate will use the opApply call (assuming ranges aren't being used).  So if we use a simple example below, what exactly is the delegate that is passed to opApply? 

> The docs say a delegate is a pairing of an object reference and a function, where the object is passed as the 'this' parameter to the function.  But that doesn't seem to be the case here.

If the docs say that, they're wrong.

Generally speaking, a delegate is a pairing of a function pointer and a context, where the context can be a struct pointer, a class reference *or a stackframe*, as is the case with opApply.

Hope that clears things up.



More information about the Digitalmars-d mailing list