www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11820] New: std.algorithm.remove does not function with `alias this`

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11820

           Summary: std.algorithm.remove does not function with `alias
                    this`
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: msoucy csh.rit.edu



Created an attachment (id=1306)
Sample file from dpaste

In situations such as the attached, std.algorithm.remove produces a
compile-time error when used on an object that fulfills its requirements only
because of `alias this`.

Issue was traced to this commit:
https://github.com/D-Programming-Language/phobos/pull/1162/files

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 25 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11820




It seems that this affects more than just std.algorithm.remove - reverse also
causes compile errors, possibly others.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11820


Matt Soucy <msoucy csh.rit.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |regression


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 01 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11820


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |monarchdodra gmail.com
         Resolution|                            |INVALID



 In situations such as the attached, std.algorithm.remove produces a
compile-time error when used on an object that fulfills its requirements only because of `alias this`. Technically, "remove" does not produce a compile time error, because the object does *not* fulfill the requirements, and the compiler finds no adequate match. remove (and reverse) require input to be at *least* a forward range. Foo is *not* a forward range because the type returned by `foo.save` is not `Foo`, it's an int[]. This violates the requirement that you can do this with a forward range: Foo f; f = f.save; //Fails -------- The two workarounds are: 1) Pass an explicit f.bar 2) Improve Foo to be an actual forward range: give it its own "save" primitive, as well as the slicing primitives (for hasSlicing). Also, don't forget to *re*-assign the result of "remove" after calling it, or you'll just observe "shuffled" elements. //---- import std.stdio; import std.algorithm; import std.range; struct Foo { int[] bar; alias bar this; inout(Foo) save() property inout { return this; } inout(Foo) opSlice(size_t i, size_t j) property inout { return inout(Foo)(bar[i .. j]); } } void main() { Foo f; static assert(isRandomAccessRange!Foo); static assert(hasSlicing!Foo); f = [1,3,5,7,9]; (f = remove(f, 0)).writeln(); (f.bar = remove(f.bar, 0)).writeln(); (f = remove(f, 0)).writeln(); (f.bar = remove(f.bar, 0)).writeln(); } //---- -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 02 2014