D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4402 - std.range.Zip doesn't work w/ non-lvalue ranges
Summary: std.range.Zip doesn't work w/ non-lvalue ranges
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-28 19:27 UTC by David Simcha
Modified: 2010-08-15 19:55 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2010-06-28 19:27:56 UTC
import std.range;

/**Random access range based on an array, but w/o assignable or lvalue
 * elements.*/
struct ValArray {
    uint[] stuff;

    @property uint front() {
        return stuff[0];
    }

    void popFront() {
        stuff = stuff[1..$];
    }

    @property bool empty() {
        return stuff.length == 0;
    }

    @property uint back() {
        return stuff[$ - 1];
    }

    void popBack() {
        stuff = stuff[0..$ - 1];
    }

    uint opIndex(size_t index) {
        return stuff[index];
    }

    @property typeof(this) save() {
        return this;
    }

    @property size_t length() {
        return stuff.length;
    }
}

void main() {
    auto stuff = ValArray([1u, 2U, 3U]);
    auto myZip = zip(stuff, stuff);
}

Error Msgs: 

d:\dmd2\windows\bin\..\..\src\phobos\std\range.d(1720): Error: cannot implicitly convert expression (&this.ranges._field_field_0.front) of type uint delegate() to uint*
d:\dmd2\windows\bin\..\..\src\phobos\std\range.d(1720): Error: cannot implicitly convert expression (&this.ranges._field_field_1.front) of type uint delegate() to uint*
d:\dmd2\windows\bin\..\..\src\phobos\std\range.d(1733): Error: cannot implicitly convert expression (&this.ranges._field_field_0.back) of type uint delegate() to uint*
d:\dmd2\windows\bin\..\..\src\phobos\std\range.d(1733): Error: cannot implicitly convert expression (&this.ranges._field_field_1.back) of type uint delegate() to uint*

Zip should detect whether the ranges it's fed offer lvalue access and properly relay this property.
Comment 1 David Simcha 2010-08-15 19:55:18 UTC
Fixed SVN.