Fix ConstexprVector::resize

This commit is contained in:
Maxime Coste 2017-10-20 19:00:06 +08:00
parent 60e32d73ff
commit 7c3bc48627
2 changed files with 6 additions and 9 deletions

View File

@ -35,7 +35,7 @@ struct HashIndex
size_t new_size = 4;
while (new_size < min_size)
new_size *= 2;
m_entries.resize(new_size, {});
m_entries.resize(new_size);
}
using ContainerType = Container<Entry, domain>;
@ -44,7 +44,7 @@ struct HashIndex
{
kak_assert(new_size > m_entries.size());
ContainerType old_entries = std::move(m_entries);
m_entries.resize(new_size, {});
m_entries.resize(new_size);
for (auto& entry : old_entries)
{
if (entry.index >= 0)

View File

@ -57,17 +57,14 @@ struct ConstexprVector
constexpr bool empty() const { return m_size == 0; }
constexpr size_t size() const { return m_size; }
constexpr void resize(size_t n, const T& val)
constexpr void resize(size_t n, const T& val = {})
{
if (n >= capacity)
throw "capacity exceeded";
if (n > m_size)
{
for (int i = n; i < m_size; ++i)
m_data[i] = val;
}
for (int i = m_size; i < n; ++i)
m_data[i] = val;
m_size = n;
kak_assert(this->size() == m_size);
kak_assert(this->size() == m_size); // check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79520
}
constexpr T& operator[](size_t i) { return m_data[i]; }