opApply not called for foeach(container)

Steven Schveighoffer schveiguy at yahoo.com
Thu Jul 12 15:02:19 PDT 2012


On Thu, 12 Jul 2012 17:35:23 -0400, monarch_dodra  
<monarch_dodra at gmail.com> wrote:

> On Thursday, 12 July 2012 at 21:18:21 UTC, Steven Schveighoffer wrote:
>>
>> If opSlice is to be used, this is how it should go (in order of  
>> precedence):
>>
>> 1. if aggr has opApply or opApplyReverse, use it.
>>
>> 2. if aggr has opSlice, and the result of aggr.opSlice() has opApply or  
>> opApplyReverse, use it.
>>
>> 3. if aggr has opSlice, and the result of aggr.opSlice() has  
>> empty/front/popfront, use it as in your 2a above.
>>
>> 4. if aggr has empty/front/popFront, use it as in your 2b above.
>>
>> 5. static or dynamic array.
>>
>> I should also note that the existence of opApply should not preclude  
>> later possibilities if that opApply can't compile for the given foreach  
>> parameters.
>>
>> -Steve
>
> 4.1:Make copy first.

Kenji's 2b does do that:


   for (auto __r = aggr;  // If aggr is copyable, saves the original range.
       !__r.empty;
       __r.popFront()) { auto e = __r.front; ...body... }


-Steve


More information about the Digitalmars-d mailing list