[llvm] [ADT] Add SmallVectorImpl::append_range (PR #93384)

Markus Böck via llvm-commits llvm-commits at lists.llvm.org
Sun May 26 01:04:19 PDT 2024


================
@@ -701,6 +701,10 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
     this->set_size(this->size() + NumInputs);
   }
 
+  template <typename RangeTy> void append_range(RangeTy &&R) {
+    this->append(R.begin(), R.end());
----------------
zero9178 wrote:

I don't think this matches `std::vector` behaviour. A range being an rvalue shouldn't propagate to the results of its iterators.
See e.g. https://godbolt.org/z/dP4ohz9hM
This is problematic if you use a range that is some adaptor over an owning range as these are often RValues. Something like `vector.append_range(otherVector)` would have different behaviour than `vector.append_range(MutableArrayRef{otherVector})`

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


More information about the llvm-commits mailing list