http://d.puremagic.com/issues/show_bug.cgi?id=5073


Rob Jacques <sandf...@jhu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, wrong-code
           Severity|normal                      |regression


--- Comment #1 from Rob Jacques <sandf...@jhu.edu> 2011-01-05 13:14:37 PST ---
In DMD 2.051, this error message has ceased to be generated for certain inputs
and instead a runtime access violation is generated. Here is a reduced test
case:

struct Bar(T) {
    T x;
    Bar dot(Bar b) { return Bar(x+b.x); }
}

void main(string[] args) {
    Bar!real   b;
    Bar!real[] data = new Bar!real[5];
    auto foobar  = map!((a){return a.dot(b); })(data);
    return;
}

Here is a modified to std.algorithm.map that works arounds this specific bug:

template map(fun...) {
    auto map(Range)(Range r) {
        static if (fun.length > 1) {
            return Map!( unaryFun!( adjoin!(staticMap!(unaryFun, fun)) ), Range
)(r);
        } else {
            static if( is(typeof(fun[0]) == delegate) ) {
                return Map!(fun, Range)(fun[0],r);
            } else {
                return Map!(unaryFun!fun, Range)(r);
            }
        }
    }
}

struct Map(alias fun, Range) if (isInputRange!(Range))
{
    Unqual!Range _input;
    static if( is(typeof(fun) == delegate) ) {
        typeof(fun) _fun;
        this(typeof(fun) dg, Range input) { _fun = dg;  _input = input; }
    } else {
        alias fun _fun;
        this(Range input) { _input = input; }
    }


    alias typeof({ return _fun(.ElementType!(Range).init); }()) ElementType;

    static if (isBidirectionalRange!(Range)) {
        @property ElementType back()    { return  _fun(_input.back); }
                  void        popBack() {         _input.popBack;    }
    }

    // Propagate infinite-ness.
    static if (isInfinite!Range)  {
        enum bool empty = false;
    } else {
        @property bool empty() { return _input.empty; }
    }

    void popFront() { _input.popFront; }

    @property ElementType front() { return _fun(_input.front); }

    static if (isRandomAccessRange!Range)
    {
        ElementType opIndex(size_t index)
        {
            return _fun(_input[index]);
        }
    }

    // hasLength is busted, Bug 2873
    static if (is(typeof(_input.length) : size_t)
        || is(typeof(_input.length()) : size_t))
    {
        @property size_t length()
        {
            return _input.length;
        }
    }

    static if (hasSlicing!(Range)) {
        typeof(this) opSlice(size_t lowerBound, size_t upperBound) {
            auto result = this;
            result._input = result._input[lowerBound..upperBound];
            return result;
        }
    }

    static if (isForwardRange!Range)
    @property Map save()
    {
        auto result = this;
        result._input = result._input.save;
        return result;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to