[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector<T> from ArrayRef of items convertible to type T

Dawid Jurczak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 21 07:09:25 PDT 2022


yurai007 added a comment.

Instead adding one more constructor another option is tweaking existing SmallVector(const iterator_range<RangeTy> &R) one in following way:

  -  template <typename RangeTy>
  -  explicit SmallVector(const iterator_range<RangeTy> &R)
  -      : SmallVectorImpl<T>(N) {
  +  template <typename Range, typename = std::enable_if_t<std::is_convertible<
  +                                ValueTypeFromRangeType<Range>, T>::value>>
  +  SmallVector(const Range &R) : SmallVectorImpl<T>(N) {
       this->append(R.begin(), R.end());
  }

That would unlock possibility of creating SmallVector not only from ArrayRef but from every range as long as types are convertible.
I didn't explore this way further, I'm not sure but I believe it should work. It's more than just "adding ArrayRef constructor" but if you are interested I can check where it leads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268



More information about the cfe-commits mailing list