This is an archive of the discontinued LLVM Phabricator instance.

[libc++] [test] Simplify (sized_)sentinel_wrapper; use it in more places.
ClosedPublic

Authored by Quuxplusone on Dec 14 2021, 4:36 PM.

Details

Summary

This is the latest installment in my series "Get rid of bogus operator== overloads that individual test files provide, for types they don't own."

Step 1 here is test_iterators.h: Ensure that sentinel_wrapper<It> is always valid and models sentinel_for<It> — even when It is an input iterator that's not equality-comparable with itself. This also brings the code style of sentinel_wrapper and sized_sentinel into line with the rest of the test iterators: use hidden-friend operators, provide an ADL base(it) function, and so on. As usual for test code, the simpler the better.

Step 2 is a handful of files that were using .base() on a sentinel. We got rid of that method in Step 1. Namely, these files were doing foo.base().base() where the inner .base() is the Standard-mandated .base() member of an STL type, and the outer .base() is the one we just removed. ADL base(foo.base()) is even a little easier on the eyes anyway. This affects range.take/sentinel/base.pass.cpp, range.take/sentinel/ctor.pass.cpp, range.transform/end.pass.cpp, range.transform/iterator/base.pass.cpp. Drive-by assert more intermediate results in all these tests.

Step 3 is types.h: Use the newly empowered sized_sentinel<It> in SizedForwardView and SizedRandomAccessView, eliminating several bogus operator- declarations! This has cascading effects in range.common.view/{begin,end}.pass.cpp (since the sentinel type of the view has changed spelling).

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Dec 14 2021, 4:36 PM
Quuxplusone created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptDec 14 2021, 4:36 PM
Quuxplusone edited the summary of this revision. (Show Details)Dec 14 2021, 4:37 PM
ldionne requested changes to this revision.Dec 15 2021, 12:31 PM

This is a really nice cleanup, however I would like the drive-by refactorings to be split into a different NFC patch.

libcxx/test/std/ranges/range.adaptors/range.take/sentinel/ctor.pass.cpp
22

Same here, please keep for the other NFC refactoring patch.

libcxx/test/std/ranges/range.adaptors/range.transform/end.pass.cpp
37 ↗(On Diff #394400)

Same here, please keep for a separate patch.

libcxx/test/std/ranges/range.adaptors/range.transform/iterator/base.pass.cpp
41 ↗(On Diff #394400)

This is the only change that actually pertains to this patch IMO, i.e. calling base(it) instead of it.base(). I like the rest of the refactoring you're doing, but can you please keep it for a separate patch?

libcxx/test/support/test_iterators.h
843–844
846
858–859

Let's not make this change in this patch -- let's do it separately.

This revision now requires changes to proceed.Dec 15 2021, 12:31 PM

Scale back to just the refactor of test_iterators.h, removal of sent.base() and its effects, and a couple of places where we should be using sized_sentinel — i.e. all the sentinel-specific stuff.
Other stuff will move to a different PR.

ldionne accepted this revision.Dec 16 2021, 8:56 AM

Thanks, this is a great cleanup and it will allow using sentinel_wrapper with non-default-constructible iterators, which was lacking.

This revision is now accepted and ready to land.Dec 16 2021, 8:56 AM
Quuxplusone marked an inline comment as done.Dec 19 2021, 7:59 AM
Quuxplusone added inline comments.
libcxx/test/std/ranges/range.adaptors/range.take/sentinel/ctor.pass.cpp
22

The NFC refactoring patch is now D116002.