www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 26] New: inout foreach does not modify BitArrays

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

           Summary: inout foreach does not modify BitArrays
           Product: D
           Version: 0.149
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: minor
          Priority: P2
         Component: Phobos
        AssignedTo: walter digitalmars.com
        ReportedBy: deewiant gmail.com


Using inout in a foreach loop through a BitArray has no effect: the bits in the
BitArray do not change when assigned to or otherwise modified.

Can be easily circumvented by using a for loop, but is still an annoyance.

--
import std.bitarray;

void main() {
        BitArray a;
        a.length = 5;
        foreach (inout bit b; a) {
                assert (b == 0);
                b = 1;
        }
        foreach (bit b; a)
                assert (b == 1); // FAILS, they're all 0
}


-- 
Mar 08 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=26





------- Comment #1 from unknown simplemachines.org  2006-03-18 18:23 -------
Created an attachment (id=4)
 --> (http://d.puremagic.com/bugzilla/attachment.cgi?id=4&action=view)
Naive, simple fix.

This adds to the unittests in bitarray.d for this bug, and calls
opIndexAssign() on each bit (before the break.)

This would seem to make foreach over bit arrays slower, but then it's still not
exceedingly fast anyway to call a function for every bit so I'd suggest the
opIndexCall isn't going to hurt anyone much.

-[Unknown]


-- 
Mar 18 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=26


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from bugzilla digitalmars.com  2006-03-20 22:21 -------
Fixed 0.150


-- 
Mar 20 2006