[PATCH] D129781: [NFC] Introduce llvm::to_vector_of to allow creation of SmallVector<T> from range of items convertible to type T

Dawid Jurczak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 00:30:04 PDT 2022


yurai007 added inline comments.


================
Comment at: llvm/include/llvm/ADT/SmallVector.h:1300-1303
+template <typename Out, typename R>
+SmallVector<Out, InlineSize<R>::value> to_vector_of(R &&Range) {
+  return {std::begin(Range), std::end(Range)};
+}
----------------
dblaikie wrote:
> Rather than an overload, can the `Size` parameter have a default value in the other definition and this overload can be removed?
The thing is we need to compute default Size from R which is Size's successor on template parameter list. We can reorder list and it would work as long as Size is default:

    template <typename Out, typename R, unsigned Size = CalculateSmallVectorDefaultInlinedElements<
                ValueTypeFromRangeType<R>>::value>
     SmallVector<Out, Size> to_vector_of(R &&Range) {
     return {std::begin(Range), std::end(Range)};
   }

However when Size is non-default both preceding types Out, R need to be passed explicitly during instantiation. If I understand it correctly, that was reason for having 2 definitions of to_vector function - for similar reason they couldn't be merged into one. It would be much easier if Size depended on Out instead but except some special scenarios when it's allowed (pointer types), in general I don't think we can rely on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129781



More information about the llvm-commits mailing list