digitalmars.D - Re: question about foreach, opApply, and delegates
- Jerry Quinn <jlquinn optonline.net> Jun 08 2009
downs Wrote: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.
Yes, that helps. All 3 replies are basically the same, and the docs are clearly insufficient to describe what's actually happening in a delegate. I'll file a bug. Thanks!
Jun 08 2009