From 277491d90b577288a77add852b4b53fe92df7e26 Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Wed, 12 Jun 2024 14:27:44 -0700 Subject: [PATCH] [libc][__support] Add constexpr to FixedVector members --- libc/src/__support/fixedvector.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libc/src/__support/fixedvector.h b/libc/src/__support/fixedvector.h index ddd0993a95272..43028a0a84637 100644 --- a/libc/src/__support/fixedvector.h +++ b/libc/src/__support/fixedvector.h @@ -25,17 +25,17 @@ template class FixedVector { constexpr FixedVector() = default; using iterator = typename cpp::array::iterator; - constexpr FixedVector(iterator begin, iterator end) { + constexpr FixedVector(iterator begin, iterator end) : store{}, item_count{} { for (; begin != end; ++begin) push_back(*begin); } - constexpr FixedVector(size_t count, const T &value) { + constexpr FixedVector(size_t count, const T &value) : store{}, item_count{} { for (size_t i = 0; i < count; ++i) push_back(value); } - bool push_back(const T &obj) { + constexpr bool push_back(const T &obj) { if (item_count == CAPACITY) return false; store[item_count] = obj; @@ -43,27 +43,27 @@ template class FixedVector { return true; } - const T &back() const { return store[item_count - 1]; } + constexpr const T &back() const { return store[item_count - 1]; } - T &back() { return store[item_count - 1]; } + constexpr T &back() { return store[item_count - 1]; } - bool pop_back() { + constexpr bool pop_back() { if (item_count == 0) return false; --item_count; return true; } - T &operator[](size_t idx) { return store[idx]; } + constexpr T &operator[](size_t idx) { return store[idx]; } - const T &operator[](size_t idx) const { return store[idx]; } + constexpr const T &operator[](size_t idx) const { return store[idx]; } - bool empty() const { return item_count == 0; } + constexpr bool empty() const { return item_count == 0; } - size_t size() const { return item_count; } + constexpr size_t size() const { return item_count; } // Empties the store for all practical purposes. - void reset() { item_count = 0; } + constexpr void reset() { item_count = 0; } // This static method does not free up the resources held by |store|, // say by calling `free` or something similar. It just does the equivalent