[PATCH] D129781: [WIP][NFC] Introduce llvm::to_vector_of to allow creation of SmallVector<T> from range of items convertible to type T
David Blaikie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 14 12:58:35 PDT 2022
dblaikie added a comment.
In D129781#3652460 <https://reviews.llvm.org/D129781#3652460>, @dexonsmith wrote:
> In D129781#3652424 <https://reviews.llvm.org/D129781#3652424>, @nikic wrote:
>
>> By the way, I think it would be worthwhile to add an `ArrayRef` constructor to SmallVector, or else drop the existing `iterator_range` ctor. I've wanted to switch an iterator_range to ArrayRef a few times in the past, and always gave up due to the SmallVector fallout. We should support both or neither.
>
> “Neither” makes some sense to me, since to_vector and to_vector_of are clear and support any range naturally. @dblaikie, any thoughts?
Yeah, I'd tend to lean that way - if std::vector doesn't have generic range-based construction, I'm happy with SmallVector not having it either.
================
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)};
+}
----------------
Rather than an overload, can the `Size` parameter have a default value in the other definition and this overload can be removed?
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