BAN: Vector now takes optional argument for default value on resize
This commit is contained in:
parent
8e626b8d1f
commit
e5c3486826
|
@ -64,7 +64,7 @@ namespace BAN
|
||||||
const T& front() const;
|
const T& front() const;
|
||||||
T& front();
|
T& front();
|
||||||
|
|
||||||
ErrorOr<void> resize(size_type);
|
ErrorOr<void> resize(size_type, const T& = T());
|
||||||
ErrorOr<void> reserve(size_type);
|
ErrorOr<void> reserve(size_type);
|
||||||
ErrorOr<void> shrink_to_fit();
|
ErrorOr<void> shrink_to_fit();
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ namespace BAN
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ErrorOr<void> Vector<T>::resize(size_type size)
|
ErrorOr<void> Vector<T>::resize(size_type size, const T& value)
|
||||||
{
|
{
|
||||||
TRY(ensure_capacity(size));
|
TRY(ensure_capacity(size));
|
||||||
if (size < m_size)
|
if (size < m_size)
|
||||||
|
@ -305,7 +305,7 @@ namespace BAN
|
||||||
m_data[i].~T();
|
m_data[i].~T();
|
||||||
if (size > m_size)
|
if (size > m_size)
|
||||||
for (size_type i = m_size; i < size; i++)
|
for (size_type i = m_size; i < size; i++)
|
||||||
new (m_data + i) T();
|
new (m_data + i) T(value);
|
||||||
m_size = size;
|
m_size = size;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue