foreach for ranges?

Ali Çehreli acehreli at yahoo.com
Wed Jul 18 11:04:41 PDT 2012


On 07/18/2012 08:21 AM, Mike L. wrote:
 >> Also, UFCS makes no sense on overloaded operators, because they 
don't get
 >> called with ".", and all UFCS is is changing obj.func(params) to
 >> func(obj,
 >> params).
 >>
 >> - Jonathan M Davis
 >
 > Ok, that's basically what I was wondering. I had assumed foreach(e;
 > someThing) {} could possibly have been converted to someThing.opApply()
 > . Thanks for clarifying.

But that is still true and opApply receives the body of the foreach loop 
as a delegate:

     someThing.opApply(delegate int(/* loop variables */) {
         // ... the body of foreach ...
         return terminationCode; // whether the user did 'break;'
     });

Also, the following bug (that is already fixed) is somewhat related to 
this discussion:

   http://d.puremagic.com/issues/show_bug.cgi?id=5605

Ali



More information about the Digitalmars-d-learn mailing list