Page MenuHomePhabricator

[STLExtras] Use return type from operator* of the wrapped iter.
ClosedPublic

Authored by fhahn on Sun, Jan 3, 8:14 AM.

Details

Summary

Currently make_early_inc_range cannot be used with iterators with
operator* implementations that do not return a reference.

Most notably in the LLVM codebase, this means the User iterator ranges
cannot be used with make_early_inc_range, which slightly simplifies
iterating over ranges while elements are removed.

Instead of directly using BaseT::reference as return type of operator*,
this patch uses decltype to get the actual return type of the operator*
implementation in WrappedIteratorT.

This patch also updates a few places to use make use of
make_early_inc_range.

Diff Detail

Event Timeline

fhahn created this revision.Sun, Jan 3, 8:14 AM
fhahn requested review of this revision.Sun, Jan 3, 8:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptSun, Jan 3, 8:14 AM

Please add some test coverage to llvm/unittests/ADT/STLExtrasTest.cpp

fhahn updated this revision to Diff 315172.Thu, Jan 7, 9:56 AM

Please add some test coverage to llvm/unittests/ADT/STLExtrasTest.cpp

Done, I added a version of the existing test with a custom iterator that returns a pointer on dereference.

dblaikie added inline comments.Thu, Jan 7, 11:12 AM
llvm/unittests/ADT/STLExtrasTest.cpp
458

std::iterator is deprecated - you could try using llvm::iterator_adaptor_base, it'll also simplify the implementation by providing default implementations of several operations required for the iterator concepts.

fhahn updated this revision to Diff 315323.Fri, Jan 8, 2:42 AM

simplified using iterator_adaptor_base, thanks!

fhahn added inline comments.Fri, Jan 8, 3:17 AM
llvm/unittests/ADT/STLExtrasTest.cpp
458

Thanks, that indeed really simplifies the code :)

dblaikie accepted this revision.Fri, Jan 8, 10:46 AM

Looks good

This revision is now accepted and ready to land.Fri, Jan 8, 10:46 AM
fhahn added a comment.Sun, Jan 10, 7:49 AM

Great, thanks for taking a look and the very helpful comments!