From dce2436b2c61a14077ad84a85c9b18e38ec66457 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 14 Sep 2024 19:44:04 +0300 Subject: [PATCH] BAN: Implement Vector::reverse() --- BAN/include/BAN/Vector.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BAN/include/BAN/Vector.h b/BAN/include/BAN/Vector.h index 039e264986..c58a111dbe 100644 --- a/BAN/include/BAN/Vector.h +++ b/BAN/include/BAN/Vector.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace BAN { @@ -65,6 +66,8 @@ namespace BAN const T& front() const; T& front(); + void reverse(); + ErrorOr resize(size_type) requires is_default_constructible_v; ErrorOr resize(size_type, const T&) requires is_copy_constructible_v; ErrorOr reserve(size_type); @@ -301,6 +304,13 @@ namespace BAN return m_data[0]; } + template + void Vector::reverse() + { + for (size_type i = 0; i < m_size / 2; i++) + BAN::swap(m_data[i], m_data[m_size - i - 1]); + } + template ErrorOr Vector::resize(size_type size) requires is_default_constructible_v {