BAN: Add requires clauses for vector

This commit is contained in:
Bananymous 2023-12-24 13:38:20 +02:00
parent 84b2438b3d
commit 6fec142760
1 changed files with 17 additions and 2 deletions

View File

@ -64,7 +64,8 @@ namespace BAN
const T& front() const;
T& front();
ErrorOr<void> resize(size_type, const T& = T());
ErrorOr<void> resize(size_type) requires is_default_constructible_v<T>;
ErrorOr<void> resize(size_type, const T&) requires is_copy_constructible_v<T>;
ErrorOr<void> reserve(size_type);
ErrorOr<void> shrink_to_fit();
@ -297,7 +298,21 @@ namespace BAN
}
template<typename T>
ErrorOr<void> Vector<T>::resize(size_type size, const T& value)
ErrorOr<void> Vector<T>::resize(size_type size) requires is_default_constructible_v<T>
{
TRY(ensure_capacity(size));
if (size < m_size)
for (size_type i = size; i < m_size; i++)
m_data[i].~T();
if (size > m_size)
for (size_type i = m_size; i < size; i++)
new (m_data + i) T();
m_size = size;
return {};
}
template<typename T>
ErrorOr<void> Vector<T>::resize(size_type size, const T& value) requires is_copy_constructible_v<T>
{
TRY(ensure_capacity(size));
if (size < m_size)