[libc-commits] [libc] [libc][__support] Add constexpr to FixedVector members (PR #95315)

via libc-commits libc-commits at lists.llvm.org
Wed Jun 12 14:29:14 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (PiJoules)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/95315.diff


1 Files Affected:

- (modified) libc/src/__support/fixedvector.h (+11-11) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/95315


More information about the libc-commits mailing list