[llvm] r205987 - iterator_range: Add an llvm::make_range() helper method.

David Blaikie dblaikie at gmail.com
Thu Apr 10 15:10:47 PDT 2014


On Thu, Apr 10, 2014 at 2:49 PM, Jim Grosbach <grosbach at apple.com> wrote:
> Author: grosbach
> Date: Thu Apr 10 16:49:22 2014
> New Revision: 205987
>
> URL: http://llvm.org/viewvc/llvm-project?rev=205987&view=rev
> Log:
> iterator_range: Add an llvm::make_range() helper method.
>
> Convenience wrapper to make dealing with sub-ranges easier. Like the
> iterator_range<> itself, if/when this sort of thing gets standards
> blessing, it will be replaced by the official version.
>
> 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=205987&r1=205986&r2=205987&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/iterator_range.h (original)
> +++ llvm/trunk/include/llvm/ADT/iterator_range.h Thu Apr 10 16:49:22 2014
> @@ -40,6 +40,14 @@ public:
>    IteratorT begin() const { return begin_iterator; }
>    IteratorT end() const { return end_iterator; }
>  };
> +
> +/// \brief Convenience function for iterating over sub-ranges.
> +///
> +/// This provides a bit of syntactic sugar to make using sub-ranges
> +/// in for loops a bit easier. Analogous to std::make_pair().
> +template<class T> iterator_range<T> make_range(const T &x, const T &y) {
> +  return (iterator_range<T>(x, y));

The extra parens seem a bit... excessive?

That was all I was going to say... but then I got bored/pedantic/something:

You could pass x and y by value and use std::move inside, since
iterator_range is going to take these things by value and do the same
thing in its ctor.

So I did that in r205993.

> +}
>  }
>
>  #endif
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list