[libc-commits] [libc] 39f7846 - [libc][__support] Add constexpr to FixedVector members (#95315)
via libc-commits
libc-commits at lists.llvm.org
Wed Jun 12 15:24:54 PDT 2024
Author: PiJoules
Date: 2024-06-12T15:24:48-07:00
New Revision: 39f78464d5f8794bc836b5e15c92fd1e162a3d0b
URL: https://github.com/llvm/llvm-project/commit/39f78464d5f8794bc836b5e15c92fd1e162a3d0b
DIFF: https://github.com/llvm/llvm-project/commit/39f78464d5f8794bc836b5e15c92fd1e162a3d0b.diff
LOG: [libc][__support] Add constexpr to FixedVector members (#95315)
Added:
Modified:
libc/src/__support/fixedvector.h
Removed:
################################################################################
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 <typename T, size_t CAPACITY> class FixedVector {
constexpr FixedVector() = default;
using iterator = typename cpp::array<T, CAPACITY>::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 <typename T, size_t CAPACITY> 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
More information about the libc-commits
mailing list