opApply not called for foeach(container)
monarch_dodra
monarch_dodra at gmail.com
Thu Jul 12 23:20:45 PDT 2012
On Thursday, 12 July 2012 at 22:02:19 UTC, Steven Schveighoffer
wrote:
> 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
Oh, right "use it as in _your_ 2b above". Didn't get what you
meant at first.
About the if "opApply can't compile": Do you mean:
a) If there is no matching opApply function?
b) Or if there is an actual error in the body of opApply?
I think you meant a) ?
I think your 1. and 2. should instead read:
1. if aggr has a matching opApply or opApplyReverse, use it.
2. if aggr has opSlice, and the result of aggr.opSlice() has a
matching opApply or opApplyReverse, use it.
More information about the Digitalmars-d
mailing list