Bug 26 – inout foreach does not modify BitArrays

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-03-08T14:01:00Z
Last change time
2014-02-15T02:15:21Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla

Attachments

IDFilenameSummaryContent-TypeSize
4bug26.diffNaive, simple fix.text/plain868

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2006-03-08T14:01:39Z
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 }
Comment #1 by bugs-d — 2006-03-18T18:23:24Z
Created attachment 4 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]
Comment #2 by bugzilla — 2006-03-20T22:21:36Z
Fixed 0.150