This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by fhahn on Jan 3 2021, 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.Jan 3 2021, 8:14 AM
fhahn requested review of this revision.Jan 3 2021, 8:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2021, 8:14 AM

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

fhahn updated this revision to Diff 315172.Jan 7 2021, 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.Jan 7 2021, 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.Jan 8 2021, 2:42 AM

simplified using iterator_adaptor_base, thanks!

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

Thanks, that indeed really simplifies the code :)

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

Looks good

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

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