From c55994f67d82824070fec934e0d01aa14d2dcb18 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 1 Feb 2024 21:06:53 -0600 Subject: [PATCH] [ox/std] Add Vector::capacity --- deps/ox/src/ox/std/vector.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 87033fda..9ccd9aba 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -239,6 +239,9 @@ class Vector: detail::VectorAllocator { [[nodiscard]] constexpr Result back() const noexcept; + [[nodiscard]] + constexpr std::size_t capacity() const noexcept; + [[nodiscard]] constexpr std::size_t size() const noexcept; @@ -424,7 +427,7 @@ constexpr const T &Vector::operator[](std::size_t template constexpr Result Vector::at(size_t i) noexcept { - if (i < size()) { + if (i < size()) [[likely]] { return &operator[](i); } return OxError(1, "Vector: Invalid index"); @@ -432,7 +435,7 @@ constexpr Result Vector::at(size_t i) noexcep template constexpr Result Vector::at(size_t i) const noexcept { - if (i < size()) { + if (i < size()) [[likely]] { return &operator[](i); } return OxError(1, "Vector: Invalid index"); @@ -470,6 +473,11 @@ constexpr Result Vector::back() const n return &m_items[m_size - 1]; } +template +constexpr std::size_t Vector::capacity() const noexcept { + return m_cap; +} + template constexpr std::size_t Vector::size() const noexcept { return m_size;