mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Fix Issue 20241 - BitArray.bitsSet ignores length
This commit is contained in:
parent
01fd74a699
commit
289149a2f1
1 changed files with 19 additions and 5 deletions
|
@ -2585,12 +2585,16 @@ public:
|
||||||
@property auto bitsSet() const nothrow
|
@property auto bitsSet() const nothrow
|
||||||
{
|
{
|
||||||
import std.algorithm.iteration : filter, map, joiner;
|
import std.algorithm.iteration : filter, map, joiner;
|
||||||
import std.range : iota;
|
import std.range : iota, chain;
|
||||||
|
|
||||||
return iota(dim).
|
return chain(
|
||||||
filter!(i => _ptr[i])().
|
iota(fullWords)
|
||||||
map!(i => BitsSet!size_t(_ptr[i], i * bitsPerSizeT))().
|
.filter!(i => _ptr[i])()
|
||||||
joiner();
|
.map!(i => BitsSet!size_t(_ptr[i], i * bitsPerSizeT))()
|
||||||
|
.joiner(),
|
||||||
|
iota(fullWords * bitsPerSizeT, _len)
|
||||||
|
.filter!(i => this[i])()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -2630,6 +2634,16 @@ public:
|
||||||
assert(b.bitsSet.equal(iota(wordBits * 2)));
|
assert(b.bitsSet.equal(iota(wordBits * 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue 20241
|
||||||
|
@system unittest
|
||||||
|
{
|
||||||
|
BitArray ba;
|
||||||
|
ba.length = 2;
|
||||||
|
ba[1] = 1;
|
||||||
|
ba.length = 1;
|
||||||
|
assert(ba.bitsSet.empty);
|
||||||
|
}
|
||||||
|
|
||||||
private void formatBitString(Writer)(auto ref Writer sink) const
|
private void formatBitString(Writer)(auto ref Writer sink) const
|
||||||
{
|
{
|
||||||
if (!length)
|
if (!length)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue