[Issue 4654] Cannot overload range iteration against opApply iteration

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Oct 31 21:55:21 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=4654

bb.temp at gmx.com changed:

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

--- Comment #2 from bb.temp at 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.

--


More information about the Digitalmars-d-bugs mailing list