[PATCH] iterator_range rebinding

Aaron Ballman aaron at aaronballman.com
Fri Mar 7 13:56:02 PST 2014

I have a situation that comes up fairly frequently in clang where we
have an iterator, and then a templated "specific" version of the
iterator. For instance decl_iterator and specific_decl_iterator,
attr_iterator and specific_attr_iterator, etc.

This patch is proposing a template constructor for iterator_range that
allows you to rebind an existing iterator_range of a different type.

This would allow me to do things like:

// In DeclBase.h
template <typename SpecificDecl>
using specific_decl_range =

decl_range decls() const;

// In Decl.h
typedef specific_decl_range<EnumConstantDecl> enumerator_range;

enumerator_range enumerators() const {
  const EnumDecl *E = getDefinition();
  if (!E)
    E = this;
  return enumerator_range(E->decls());

Is this a reasonable approach, or is there a better way?  Thanks!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterator_range.h.patch
Type: application/octet-stream
Size: 610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140307/2e5c1a36/attachment.obj>

More information about the llvm-commits mailing list