[libc-commits] [PATCH] D118954: [libc] add a vector internal class

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Feb 9 13:17:19 PST 2022


michaelrj marked 3 inline comments as done.
michaelrj added inline comments.


================
Comment at: libc/src/__support/CPP/vector.h:50
+  // undefined.
+  constexpr void resize(size_t new_size) {
+    if (new_size >= array_size)
----------------
sivachandra wrote:
> I still don't understand the argument for having a resize method. Also, it is not inserting any elements for a size increase. So, it is different from `std::vector` behavior.
if you look on line 36 of vector_test.cpp you can see an example usage of this function. There needs to be some way of resizing this array other than push_back, since one of the intended use cases is writing out of order. I need some way of increasing the size (represented by num_elements) as well as the capacity (represented by array_size). If you have a better idea for how to do that please share it. If it would help I can rename this class so that there's no confusion with the `std::vector` class.


================
Comment at: libc/src/__support/CPP/vector.h:65
+    if (pos >= num_elements)
+      num_elements = pos + 1;
+    return data_array[pos];
----------------
sivachandra wrote:
> I don't think is still correct. For one, `std::vector::operator[]` does not insert a new element.
I forgot to remove that code in the previous patch. Fixed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118954/new/

https://reviews.llvm.org/D118954



More information about the libc-commits mailing list