Thread overview
[Issue 4597] New: std.algorithm.filter fails with a const range
Aug 08, 2010
Brad Roberts
Aug 08, 2010
Brad Roberts
Sep 15, 2011
yebblies
August 08, 2010
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


--- Comment #0 from Brad Roberts <braddr@puremagic.com> 2010-08-07 22:29:10 PDT ---
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: -------
August 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4597


Andrei Alexandrescu <andrei@metalanguage.com> changed:

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


--- Comment #1 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-08-07 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: -------
August 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4597



--- Comment #2 from Brad Roberts <braddr@puremagic.com> 2010-08-07 22:56:28 PDT ---
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: -------
September 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4597


yebblies <yebblies@gmail.com> changed:

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


--- Comment #3 from yebblies <yebblies@gmail.com> 2011-09-15 12:16:36 EST ---
(In reply to comment #1)
> 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: -------