[llvm-dev] ArrayRef vs SmallVectorImpl

Arsenault, Matthew via llvm-dev llvm-dev at lists.llvm.org
Fri May 3 09:42:08 PDT 2019

You can’t append to an ArrayRef

From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of llvm-dev <llvm-dev at lists.llvm.org>
Reply-To: Russell Wallace <russell.wallace at gmail.com>
Date: Friday, May 3, 2019 at 6:39 PM
To: llvm-dev <llvm-dev at lists.llvm.org>
Subject: [llvm-dev] ArrayRef vs SmallVectorImpl

It is suggested in the documentation that if you would have declared a function parameter as SmallVector<Foo,N>&, it is better to instead declare it as SmallVectorImpl<Foo>&.

This makes sense, but it seems to me that it is better still to declare it as ArrayRef<Foo>; a quick test suggests it compiles to the same (highly efficient) code, and adds a bit more flexibility in case e.g. you someday want to pass a std::vector.

By that logic, there is never any reason to take a SmallVectorImpl, because ArrayRef is strictly better. Am I missing anything?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190503/ce1a9f79/attachment.html>

More information about the llvm-dev mailing list