www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9507] New: std.range.transposed behaves poorly with jagged ranges of ranges

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

           Summary: std.range.transposed behaves poorly with jagged ranges
                    of ranges
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx



If you pass a jagged range of ranges to std.range.transposed, once one of the
subranges is consumed, .front will cause an invalid access to the empty
subrange's .front, causing a runtime error.

However, the returned range's .empty will still be false, even though you can't
safely use .front anymore!

So std.range.transposed should either return empty if *any* of its ranges are
empty, or else, its .front should be modified so that empty subranges will be
skipped over (or should there be an option to specify a default element?).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9507


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc




 If you pass a jagged range of ranges to std.range.transposed, once one of the
 subranges is consumed, .front will cause an invalid access to the empty
 subrange's .front, causing a runtime error.
 
 However, the returned range's .empty will still be false, even though you can't
 safely use .front anymore!
 
 So std.range.transposed should either return empty if *any* of its ranges are
 empty, or else, its .front should be modified so that empty subranges will be
 skipped over (or should there be an option to specify a default element?).
This shows some usages the stadard Haskell function transpose, I'd like the D version to do something similar. No need for a default element: Prelude> import Data.List (transpose) Prelude Data.List> transpose [[1,2,3],[4,5,6],[7,8,9]] [[1,4,7],[2,5,8],[3,6,9]] Prelude Data.List> let a = [[7,4,2,8,7],[8,0,8],[3],[1,6,0,7,7,2,0],[8,9,3,1],[6],[6]] Prelude Data.List> transpose a [[7,8,3,1,8,6,6],[4,0,6,9],[2,8,0,3],[8,7,1],[7,7],[2],[0]] Prelude Data.List> transpose [[1],[],[3,4]] [[1,3],[4]] -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 03 2013