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

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Feb 9 13:29:44 PST 2022

sivachandra accepted this revision.
sivachandra added a comment.
This revision is now accepted and ready to land.

OK with the method name and semantic change as commented inline.

Comment at: libc/src/__support/CPP/vector.h:50
+  // undefined.
+  constexpr void resize(size_t new_size) {
+    if (new_size >= array_size)
michaelrj wrote:
> 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.
OK. So what you want really is a `reserve` method? FWIW, `std::vector` has a reserve method and the only change you will need is to remove line 53 below.

  rG LLVM Github Monorepo



More information about the libc-commits mailing list