[LLVMdev] [RFC] Add empty() method to iterator_range. (original) (raw)
Lang Hames lhames at gmail.com
Fri Mar 21 10:28:40 PDT 2014
- Previous message: [LLVMdev] [RFC] Add empty() method to iterator_range.
- Next message: [LLVMdev] [RFC] Add empty() method to iterator_range.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Chandler,
Agreed - ranges aren't containers, just views of sequences. Still, that's all many algorithms want, and it's just as valid to ask whether a sequence is empty as it is to ask that of a container.
No contest on points 2 or 3, but I'm confused about point 4. When are ranges not pairs of iterators? I mean in a way that would clash with the proposal for empty() to be defined as '(begin(r) == end(r)' ?
The benefit of doing this is similar in kind, though obviously less significant, to the benefit of range based for loops. It doesn't enable anything fundamentally new, but improving readability of C++ code is welcome.
This is easy to punt (and I won't be especially bothered if that's what we do), but it also seems like it would be easy to implement our own version (llvm::is_empty?) and replace it when the committee decides on something, the same way we did with llvm::move? Is there any reason not to follow that approach?
Cheers, Lang.
On Thu, Mar 20, 2014 at 2:31 PM, Chandler Carruth <chandlerc at google.com>wrote:
Since Richard first poked me about this, I'm still debating this.
I'm torn in a bunch of different ways: 1) iteratorrange is not a container. It shouldn't and can't be used like one. 2) members are really hard to extend. they make templates harder not easier because the widen the set of interfaces which must be on a given container 3) the concept of testing for emptiness is actually inherently useful for all ranges, unlike many other proposed extensions to the member interface, so maybe its OK to grow the interface in this direction 4) basing emptiness on iterators seems really bad because one of the important utilities of ranges is that they may expose concepts which are more flexible and efficient than a pair of iterators However, one thing makes me inclined to say "no" to this: the benefit is miniscule. It is too simple to just compare the iterators and not cross any of these bridges today. On Wed, Mar 19, 2014 at 11:57 AM, Duncan P. N. Exon Smith <_ _dexonsmith at apple.com> wrote:
> This is a pattern I ran into a handful of times when range-ifying > parts of clang (but not so frequently that I felt it was a major win), > so I'm roughly in favor of the API. However, if there's been > standardization efforts for range, we should be sure that we're doing > something compatible there.
There are a couple of proposals [1][2] that I can find. It sounds like the exact set of methods to provide is somewhat contentious [3]. empty() seems pretty innocuous though. Note that the standard proposals use std::range instead of std::iteratorrange. In my opinion, other methods (e.g., front(), back(), and (for random access iterators) operator[]) would also be useful. I think front, back, and [] are extremely contentious. =] While empty may be the most innocuous, it also seems the least useful today.
LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140321/2db76925/attachment.html>
- Previous message: [LLVMdev] [RFC] Add empty() method to iterator_range.
- Next message: [LLVMdev] [RFC] Add empty() method to iterator_range.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]