www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4597] New: std.algorithm.filter fails with a const range

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

           Summary: std.algorithm.filter fails with a const range
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: braddr puremagic.com



---
Index: std/algorithm.d
===================================================================
--- std/algorithm.d     (revision 1807)
+++ std/algorithm.d     (working copy)
   -830,6 +830,9   

     // With chain
     assert(equal(filter!overX(chain(a, nums)), [22, 42]));
+
+    const int[] list = [ 1, 2, 10, 11, 3, 4 ];
+    assert(equal(filter!overX(list), [ 1, 2, 10, 3, 4 ]));
 }

 // move

Adding that test produces the folling failure:
std/algorithm.d(737): Error: this is not mutable

That's the opSlice function of struct Filter:
            ref Filter opSlice()
            {
                return this;
            }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 07 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4597


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com



22:37:26 PDT ---
This is quite problematic. Most of std.algorithm fails on const and immutable
arrays because it does not do the conversion const(int[]) -> const(int)[] and
immutable(int[]) -> immutable(int)[], both of which are legal.

I'm not sure how this can be addressed. A brute force solution would be to
special-case all algorithms for certain array types, but that would be
horrible. Ideas are welcome.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 07 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4597




---
note, the assert is wrong, should be:
assert(equal(filter!overX(list), [ 11 ]));

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 07 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4597


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com




 I'm not sure how this can be addressed. A brute force solution would be to
 special-case all algorithms for certain array types, but that would be
 horrible. Ideas are welcome.
One idea is issue 6289 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 14 2011