www.digitalmars.com         C & C++   DMDScript  
Archives

D Programming
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger
D.gnu
D

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics


digitalmars.D - Re: question about foreach, opApply, and delegates

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