Skip to content

[libc][__support] Add constexpr to FixedVector members #95315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

PiJoules
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jun 12, 2024

@llvm/pr-subscribers-libc

Author: None (PiJoules)

Changes

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

1 Files Affected:

  • (modified) libc/src/__support/fixedvector.h (+11-11)
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

@PiJoules PiJoules merged commit 39f7846 into llvm:main Jun 12, 2024
6 of 7 checks passed
@PiJoules PiJoules deleted the fixedvector-constexpr-funcs branch June 12, 2024 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants