Skip to content

Commit

Permalink
Merge pull request #6742 from RichardPalme/fix-bitmanip-count
Browse files Browse the repository at this point in the history
fixed issue 19338
merged-on-behalf-of: Nathan Sashihara <n8sh@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Oct 30, 2018
2 parents 67cc148 + 9d7f453 commit 9fcf1f1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions std/bitmanip.d
Expand Up @@ -1362,11 +1362,18 @@ public:
*/
size_t count()
{
size_t bitCount;
foreach (i; 0 .. fullWords)
bitCount += countBitsSet(_ptr[i]);
bitCount += countBitsSet(_ptr[fullWords] & endMask);
return bitCount;
if (_ptr)
{
size_t bitCount;
foreach (i; 0 .. fullWords)
bitCount += countBitsSet(_ptr[i]);
bitCount += countBitsSet(_ptr[fullWords] & endMask);
return bitCount;
}
else
{
return 0;
}
}

///
Expand All @@ -1375,6 +1382,9 @@ public:
auto a = BitArray([0, 1, 1, 0, 0, 1, 1]);
assert(a.count == 4);

BitArray b;
assert(b.count == 0);

bool[200] boolArray;
boolArray[45 .. 130] = true;
auto c = BitArray(boolArray);
Expand Down

0 comments on commit 9fcf1f1

Please sign in to comment.