[PATCH] D30853: Improve the genericity of `llvm::enumerate()`.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 12 22:57:27 PDT 2017


Yea, the main reason is because this pattern could be used to allow
conversion even to types we don't control, like set or deque. Also a range
constructor might be confusing since many containers use a single argument
constructor to indicate the initial size (SFINAE would make it work, but I
like to avoid it when possible to make the code easier to understand)
On Sun, Mar 12, 2017 at 10:52 PM David Blaikie <dblaikie at gmail.com> wrote:

>
>
> On Sun, Mar 12, 2017, 10:49 PM Chandler Carruth via Phabricator <
> reviews at reviews.llvm.org> wrote:
>
> chandlerc added inline comments.
>
>
> ================
> Comment at: llvm/include/llvm/ADT/STLExtras.h:891-897
> +/// \brief Given a range of type R, iterate the entire range and return a
> +/// SmallVector with elements of the vector.  This is useful, for example,
> +/// when you want to iterate a range and then sort the results.
> +template <unsigned Size, typename R>
> +SmallVector<detail::ValueOfRange<R>, Size> to_vector(R &&Range) {
> +  return {std::begin(Range), std::end(Range)};
> +}
> ----------------
> Why not a range constructor for SmallVector?
>
>
> Fair, I wouldn't mind that. But I did check and std::vector doesn't have
> one I don't think, so I figured for consistency and that this could grow to
> allow other kinds of ranges to be constructed.
>
>
>
> https://reviews.llvm.org/D30853
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170313/4c7d593a/attachment.html>


More information about the llvm-commits mailing list