[PATCH] D46668: [STLExtras] Add a range-based distance()

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon May 14 11:58:59 PDT 2018


I feel like a range-based version of std::distance isn't so much distance
anymore, by virtue of it being over a range & is actually probably more
suitably named 'size'. (in the case of std::distance, the name is really
talking about the two elements separately "what's the distance from this
iterator to this other iterator" not talking about a range defined by those
two iterators - so the name make sense there in a way that I don't think it
makes sense for ranges ("what is the distance of a range?" isn't a
cromulant question, I think... ))

I'd vote for llvm::size (& I think the general idea/concept/thing is a good
thing to add).

Though I guess one issue with size/distance is: how expensive is this? I'd
sort of be inclined only to provide this for ranges over random access
iterators (so it's only O(1), never O(N)), maybe? Let the more obscure
cases use std::distance(begin, end) to hopefully clarify that they're
weird/interesting/maybe expensive.

On Thu, May 10, 2018 at 11:30 AM Craig Topper via Phabricator via
llvm-commits <llvm-commits at lists.llvm.org> wrote:

> craig.topper added a comment.
>
> I think if its equivalent to range-based version of std::distance its name
> should be llvm::distance.
>
> My comment was just an observation that a majority of the uses were for
> predecessors/successors and maybe we should just make that easier. We
> already have pred_empty and succ_empty. pred_size and succ_size don't seem
> like much of a stretch.
>
>
> https://reviews.llvm.org/D46668
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180514/7edeb46a/attachment.html>


More information about the llvm-commits mailing list