Skip to content

Commit

Permalink
Fix karray fill constructor (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
csujedihy authored Jul 18, 2024
1 parent f88a456 commit 0e59424
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions inc/karray.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,14 @@ class KRTL_CLASS KArray :
PAGED T *operator->() const { return &(*this->_a)[this->_i]; }
};

PAGED KArray(size_t sizeHint = 0, const T &value = (T)0) noexcept
PAGED KArray(size_t count = 0, const T &value = (T)0) noexcept
{
if (sizeHint)
if (count)
{
(void)grow(sizeHint);
for (ULONG i = 0; i < m_numElements; i++)
(void)grow(count);
for (ULONG i = 0; i < count; i++)
_p[i] = value;
m_numElements = static_cast<ULONG>(count);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/test/lib/VectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ void VectorBasic()
TEST_EQUAL(Array[i - 1], i);
}

CxPlatVector<uint32_t> ArrayWithSizeHint(10);
CxPlatVector<uint32_t> ArrayFill(10);
TEST_EQUAL(ArrayFill.size(), 10u);

// Verify that the newly appended element will be inserted at 10-th slot.
ArrayFill.push_back(10);
TEST_EQUAL(ArrayFill.size(), 11u);
TEST_EQUAL(ArrayFill[10], 10u);
}

0 comments on commit 0e59424

Please sign in to comment.