This is an archive of the discontinued LLVM Phabricator instance.

[libc++] [test] Change a lot of free begin/end pairs to members. NFCI.
ClosedPublic

Authored by Quuxplusone on Oct 6 2021, 7:29 AM.

Details

Summary

If you have a begin() const member, you don't need a begin() member unless you want it to do something different (e.g. have a different return type). So in general, view types don't need begin() non-const members.

Also, static_assert some things about the types in "types.h", so that we don't accidentally break those properties under refactoring.

(This came out of my attempts to make a "test_iterators.h" PR along the lines of @jloser's sized_sentinel<It>. It turned out that in many of the places we'll want to use sized_sentinel<It>, we currently have to use twice as much of it as necessary, because of all these places that use two free functions when one member would suffice. I believe I've been careful not to change any of the places that were actually trying to test our behavior on free begin/end, e.g. in the tests for std::ranges::begin.)

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Oct 6 2021, 7:29 AM
Quuxplusone created this revision.
Herald added a reviewer: Restricted Project. · View Herald TranscriptOct 6 2021, 7:29 AM
Mordante accepted this revision as: Mordante.Oct 6 2021, 10:32 AM
Mordante added a subscriber: Mordante.

Maybe mention in the commit message why changing from friends to member functions.

I assume you plan a followup to resolve the new todos?

LGTM, one small suggestion.

libcxx/test/std/ranges/range.adaptors/range.transform/types.h
21

While you're at it, maybe adding explicit in this file too?

ldionne accepted this revision.Oct 6 2021, 10:52 AM

LGTM with @Mordante 's suggestion.

libcxx/test/std/ranges/range.adaptors/range.common.view/types.h
130

Ehm good catch.

This revision is now accepted and ready to land.Oct 6 2021, 10:52 AM
Quuxplusone marked an inline comment as done.Oct 6 2021, 11:55 AM
Quuxplusone added inline comments.
libcxx/test/std/ranges/range.adaptors/range.common.view/types.h
35–37

@ldionne @Mordante: I propose a separate commit to globally replace the name ContiguousView with MoveOnlyView, since that seems to be its actual raison d'etre. (This affects several of these "types.h" files.)

libcxx/test/std/ranges/range.adaptors/range.join.view/types.h
136

This was certainly a typo in the original commit (I will keep linking to https://quuxplusone.github.io/blog/2019/01/03/const-is-a-contract/ until people start reading it! :)) but since the unit tests currently don't seem to care, I don't care to dig deeper either.
It's not as simple as making this InputValueIter<const T>, since InputValueIter defines its value_type without any remove_cv_t.