This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][ranges] Add `views::counted` CPO.
ClosedPublic

Authored by zoecarver on Jul 27 2021, 4:51 PM.

Details

Reviewers
ldionne
cjdb
Group Reviewers
Restricted Project
Commits
rGf9e58f35e905: [libcxx][ranges] Add `views::counted` CPO.

Diff Detail

Event Timeline

zoecarver created this revision.Jul 27 2021, 4:51 PM
zoecarver requested review of this revision.Jul 27 2021, 4:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2021, 4:51 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
zoecarver updated this revision to Diff 362232.Jul 27 2021, 4:54 PM

Go through list of things in the docs.

ldionne requested changes to this revision.Jul 28 2021, 7:17 AM
ldionne added inline comments.
libcxx/include/__ranges/counted.h
39

Throughout, could you use _Iter instead of _Tp and perhaps __it instead of __t? I think it conveys the meaning a bit better.

libcxx/test/std/ranges/range.adaptors/range.counted/counted.pass.cpp
1

We need to test that views::counted is a CPO, see http://eel.is/c++draft/customization.point.object.

3

Can you add a test that views::counted(iter, diff) is SFINAEd out when diff is not convertible to the iter_difference_t of iter, per http://eel.is/c++draft/range.adaptors#range.counted-2?

29

I'm not immediately seeing why this is std::span<const int> and not std::span<int>, can you explain?

73

Can you also add a test with a forward_iterator?

This revision now requires changes to proceed.Jul 28 2021, 7:17 AM
zoecarver marked 3 inline comments as done.Jul 28 2021, 11:21 AM
zoecarver added inline comments.
libcxx/test/std/ranges/range.adaptors/range.counted/counted.pass.cpp
1

Added a test for semiregular. Are there other tests you want? Maybe noexcept tests?

73

Good idea. But I don't think forward iterator tests that much new stuff, so I added tests for cpp20_input_iterator and output_iterator.

zoecarver marked an inline comment as done.

Address Louis' comments.

ldionne requested changes to this revision.Jul 28 2021, 12:31 PM
ldionne added inline comments.
libcxx/include/__ranges/counted.h
43
libcxx/test/std/ranges/range.adaptors/range.counted/counted.pass.cpp
1

I think that's fine.

29

Also, can you please static_assert(std::is_same_v<decltype(std::views::counted(...)), what-you-expect>);. Otherwise, we're potentially relying on conversions between span-to-const and span-to-non-const.

Let's figure out the const situation below, because it makes little sense to my understanding.

52

Can you also add tests for contiguous_iterator<int const*>? And for all the other iterator categories below.

This revision now requires changes to proceed.Jul 28 2021, 12:31 PM
zoecarver marked 5 inline comments as done.Jul 28 2021, 2:52 PM
zoecarver updated this revision to Diff 362549.Jul 28 2021, 2:53 PM

Apply Louis' feedback.

ldionne accepted this revision.Jul 29 2021, 7:34 AM
This revision is now accepted and ready to land.Jul 29 2021, 7:34 AM

Based on the CI failures, you've got some missing #include. Ship it once the CI is happy!

tcanens added inline comments.
libcxx/include/__ranges/counted.h
43

There are things that are implicitly-but-not-explicitly convertible to iter_difference_t<_Iter>, in which case this compiles but the wording calls for rejection.

48

Why the static_cast to the same type?

The forward is also unnecessary - the to_address overload for non-pointers should take by const& anyway.

61

For __sent shouldn't it be a move?

Quuxplusone added inline comments.
libcxx/include/__ranges/counted.h
61

Yes, and naming-bikeshed: can we call it __last instead of __sent? __sent looks like it should be a variable of type _Sent/_Sp, not an _Iter.
IOW, seeing forward<_Iter>(__sent) was the red flag here.

Also on line 56, noexcept(ranges::subrange(_VSTD::forward<_Iter>(__it), _VSTD::__decay_copy(__it)))
or something like that. Gross. Does the standard say "expression-equivalent" so we have to get this right? or is leaving it as non-noexcept an option?

libcxx/test/std/ranges/range.adaptors/range.counted/counted.pass.cpp
29

@ldionne: The situation here is easy, unless I'm mistaken: std::views::counted((int*)iter, 8) returns a span<int>, which is implicitly convertible to span<const int>, so that's what happens.
I agree that there should be a static_assert on the actual decltype, because actually tons of types are implicitly convertible to span<const int>. Including subrange<int*,int*>, for example, which would totally not be the conforming type to return here.

zoecarver updated this revision to Diff 363213.Jul 30 2021, 2:59 PM
zoecarver marked 4 inline comments as done.

Apply review comments. Fix build.

libcxx/include/__ranges/counted.h
48

Now that the second parameter is a template type parameter type I'm going to keep the static_cast.

zoecarver updated this revision to Diff 363234.Jul 30 2021, 4:25 PM

Fix build again.

zoecarver updated this revision to Diff 365298.Aug 9 2021, 3:16 PM

Fix the 32 bit bots.

Fix the 32 bit bots for real.

This revision was automatically updated to reflect the committed changes.