[llvm] r242823 - Add some utilities to iterator_range for trimming a range and constructing one from a container.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 12 13:58:05 PDT 2018


Tricky to locally scope the using directive when using the expression in
the return type - but STLExtras.h now has adl_begin/adl_end that handles
this - so you could switch it over to those & add some tests if you like :)

On Tue, Jun 12, 2018 at 1:55 PM Justin Bogner <mail at justinbogner.com> wrote:

> David Blaikie <dblaikie at gmail.com> writes:
> > Author: dblaikie
> > Date: Tue Jul 21 13:37:12 2015
> > New Revision: 242823
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=242823&view=rev
> > Log:
> > Add some utilities to iterator_range for trimming a range and
> > constructing one from a container.
> >
> > To be used in clang in a follow-up commit.
> >
> > Modified:
> >     llvm/trunk/include/llvm/ADT/iterator_range.h
> >
> > Modified: llvm/trunk/include/llvm/ADT/iterator_range.h
> > URL:
> >
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/iterator_range.h?rev=242823&r1=242822&r2=242823&view=diff
> >
> ==============================================================================
> >
> > --- llvm/trunk/include/llvm/ADT/iterator_range.h (original)
> > +++ llvm/trunk/include/llvm/ADT/iterator_range.h Tue Jul 21 13:37:12 2015
> > @@ -20,6 +20,7 @@
> >  #define LLVM_ADT_ITERATOR_RANGE_H
> >
> >  #include <utility>
> > +#include <iterator>
> >
> >  namespace llvm {
> >
> > @@ -32,6 +33,12 @@ class iterator_range {
> >    IteratorT begin_iterator, end_iterator;
> >
> >  public:
> > +  //TODO: Add SFINAE to test that the Container's iterators match the
> range's
> > +  //      iterators.
> > +  template <typename Container>
> > +  iterator_range(Container &&c)
> > +  //TODO: Consider ADL/non-member begin/end calls.
> > +      : begin_iterator(c.begin()), end_iterator(c.end()) {}
> >    iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
> >        : begin_iterator(std::move(begin_iterator)),
> >          end_iterator(std::move(end_iterator)) {}
> > @@ -51,6 +58,11 @@ template <class T> iterator_range<T> mak
> >  template <typename T> iterator_range<T> make_range(std::pair<T, T> p) {
> >    return iterator_range<T>(std::move(p.first), std::move(p.second));
> >  }
> > +
> > +template<typename T>
> > +iterator_range<decltype(begin(std::declval<T>()))> drop_begin(T &&t,
> int n) {
> > +  return make_range(std::next(begin(t), n), end(t));
>
> Sorry for the commit necromancy, but should these be std::begin and
> std::end, or perhaps have locally scoped using directives? As is this
> doesn't seem to work for llvm:: types like SmallVector.
>
> > +}
> >  }
> >
> >  #endif
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180612/2ef5d72b/attachment.html>


More information about the llvm-commits mailing list