Thread overview
[Issue 4654] Cannot overload range iteration against opApply iteration
Oct 31, 2015
Infiltrator
Nov 01, 2015
bb.temp@gmx.com
Mar 21, 2020
Basile-z
October 31, 2015
https://issues.dlang.org/show_bug.cgi?id=4654

Infiltrator <lt.infiltrator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lt.infiltrator@gmail.com

--- Comment #1 from Infiltrator <lt.infiltrator@gmail.com> ---
The issue is that the opApply delegate takes three ints, so obviously it won't compile if you pass only one.  I know that with AAs you can do both foreach(value) and foreach(key,value); but I'm not sure how exactly that's implemented.

Having said that, this bug report does highlight a problem with the error message and it should stay open until it is fixed.

Current (2.068) message:
Error: cannot infer argument types, expected 3 arguments, not 1

As for what it should be, I don't really have any good suggestions.

--
November 01, 2015
https://issues.dlang.org/show_bug.cgi?id=4654

bb.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bb.temp@gmx.com
         Resolution|---                         |INVALID

--- Comment #2 from bb.temp@gmx.com ---
(In reply to Infiltrator from comment #1)
> The issue is that the opApply delegate takes three ints, so obviously it won't compile if you pass only one.  I know that with AAs you can do both foreach(value) and foreach(key,value); but I'm not sure how exactly that's implemented.
> 
> Having said that, this bug report does highlight a problem with the error message and it should stay open until it is fixed.
> 
> Current (2.068) message:
> Error: cannot infer argument types, expected 3 arguments, not 1
> 
> As for what it should be, I don't really have any good suggestions.

No you don't get the point. The problem is that dmd recognizes both InputRange or opApply() as foreach aggregate argument. The OP expected the InpuRange to be used in the first case and opApply in the second:

---
foreach(elem; range) {}  // should use front/empty/popFront
foreach(e1, e2, e3; range) {}  // should use opApply
---

Actually this issue is invalid because the behavior is specified:

http://dlang.org/statement.html#foreach-with-ranges

> if the aggregate expression is a struct or class object, but the opApply for foreach, or opApplyReverse foreach_reverse do not exist, then iteration over struct and class objects can be done with range primitives

Meaning: if opApply is not present then look for InputRange primitives.

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=4654

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--