[LLVMdev] [RFC] Add empty() method to iterator_range.

Lang Hames lhames at gmail.com
Thu Mar 20 10:51:09 PDT 2014


Hi All,

Thanks for the feedback.
CC'ing cfe-dev, since they may have thoughts on this too.

> I think this should be
>
> bool empty() const { return begin() == end(); }

Yes. Yes it should. Though you have to admit, my version would have sped up
a lot of passes in the general case: if (Fn.blocks.empty())...

;)

For this reason I'd personally consider writing this as a free
> function over ranges:
>
> template<typename T>
> bool is_empty(T t) { return begin(t) == end(t); }
>

I have a knee-jerk dislike of free functions, just because they break with
the existing container interface. That said they have two concrete
advantages:

1) With a free function you get 'empty' for free if you implement a new
range type (e.g. array_range).
2) You can specialize is_empty for types where (for whatever bizarre
reason) testing emptiness is cheap but constructing iterators is expensive.

Whether that's worth breaking the existing idiom for, I don't know. I'm
going to have to have a read through Duncan's links to get some more
perspective (thanks for those Duncan!).

- Lang.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140320/82af2394/attachment.html>


More information about the llvm-dev mailing list