[cfe-commits] [patch] TransformIterator (motivating use case in Clang)

David Blaikie dblaikie at gmail.com
Sun May 6 19:02:25 PDT 2012

This patch adds an iterator much like boost's transform_iterator
(without some extra bells & whistles) for use in some changes I'd like
to make to Clang to correct some misimplemented iterators there.

A few gotchas that could be improved/changed depending on opinions:
* I may be playing a little loose with the return type of the functor
(see the example/motivating functor, to_pointer) - the return type
actually must be a reference, though the result_type provides the
underlying value type, not the reference type. If this is violated
Clang will emit a warning, but I could make it more robust with a
compile time assertion in the TransformIterator that the result_type
is actually a reference type, and strip that off to provide the
value_type of the TransformIterator.
* I realize adding pointer-yness back onto an iterator over references
when the underlying data structure (in the Clang patch you can see
this situation) is a sequence of pointers may be a bit overkill -
though the alternatives are writing different algorithms in the two
cases where I've used TransformIterator, or having the decl_iterator
iterate over pointers (in which case I should probably change the
other iterators I've modified to iterate over pointers for symmetry).

At some point I'll also be looking to add a FilterIterator (& possibly
a specific Filtering+Transforming iterator, as I'm not sure the
composition of the two independently will be great for the use case I
have in mind) as well since that's one of the motivation for tidying
up these iterators - to pull out the common functionality in the
specific/filtered_iterators in DeclContext.

- David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TransformIterator_clang_usage.diff
Type: application/octet-stream
Size: 40303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120506/a734aa43/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TransformIterator.diff
Type: application/octet-stream
Size: 4008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120506/a734aa43/attachment-0001.obj>

More information about the cfe-commits mailing list