From 6fec142760d66c8df1c6a2816b19b9a36360b239 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 24 Dec 2023 13:38:20 +0200 Subject: [PATCH] BAN: Add requires clauses for vector --- BAN/include/BAN/Vector.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/BAN/include/BAN/Vector.h b/BAN/include/BAN/Vector.h index 43fc872046..2a59ab6bd7 100644 --- a/BAN/include/BAN/Vector.h +++ b/BAN/include/BAN/Vector.h @@ -64,7 +64,8 @@ namespace BAN const T& front() const; T& front(); - ErrorOr resize(size_type, const T& = T()); + ErrorOr resize(size_type) requires is_default_constructible_v; + ErrorOr resize(size_type, const T&) requires is_copy_constructible_v; ErrorOr reserve(size_type); ErrorOr shrink_to_fit(); @@ -297,7 +298,21 @@ namespace BAN } template - ErrorOr Vector::resize(size_type size, const T& value) + ErrorOr Vector::resize(size_type size) requires is_default_constructible_v + { + 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 + ErrorOr Vector::resize(size_type size, const T& value) requires is_copy_constructible_v { TRY(ensure_capacity(size)); if (size < m_size)