www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20928] New: Overloaded opIndex confuses MapResult


          Issue ID: 20928
           Summary: Overloaded opIndex confuses MapResult
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: rmanth gmail.com

struct Always3
    enum empty = false;
    auto save() { return this; }
    long front() { return 3; }
    void popFront() {}
    long opIndex(size_t i) { return 3; }
    long opIndex(size_t i) immutable { return 3; };

void main()
    import std.algorithm.iteration : map;


Error: function std.algorithm.iteration.MapResult!(unaryFun,
Always3).MapResult.opIndex(uint index) is not callable using argument types

MapResult checks if it can call opIndex with ulong.max and fails for some
reason. Changing the check from is(typeof(_input[ulong.max])) to is(typeof(()
=> _input[ulong.max])) fixes the problem.

Jun 13 2020