Page MenuHomePhabricator

[libc++] Implement P2446R2 (views::as_rvalue)
ClosedPublic

Authored by philnik on Nov 8 2022, 6:05 AM.

Details

Diff Detail

Event Timeline

philnik created this revision.Nov 8 2022, 6:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2022, 6:05 AM
philnik requested review of this revision.Nov 8 2022, 6:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2022, 6:05 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik updated this revision to Diff 474255.Nov 9 2022, 6:35 AM

Address Arthur's comments

philnik updated this revision to Diff 474259.Nov 9 2022, 6:43 AM

Remove non-ASCII character

philnik updated this revision to Diff 474521.Nov 10 2022, 5:17 AM

Add deduction guide

huixie90 added inline comments.Nov 10 2022, 6:43 AM
libcxx/include/__ranges/as_rvalue_view.h
52

might be worth testing that if underlying iterator is already a move_iterator, this is calling the move constructor of move_iterator instead of creating a move_iterator<move_iterator<It>>

ldionne requested changes to this revision.Dec 1 2022, 9:23 AM

@var-const Can you make a pass at this?

libcxx/include/__iterator/move_sentinel.h
53

Can you please add a simple test that exercises this ctad, even if it is the default-provided one by the compiler?

libcxx/include/__ranges/as_rvalue_view.h
62

Do you have tests for a simple view and a non-simple view?

75

Do you have tests for a common range and a non-common range?

95

Do you have a test that would fail if you dropped the all_t here?

104

This [[nodiscard]] is an extension, so it should be using _LIBCPP_NODISCARD_EXT unless I am mistaken. Please make sure we have a libc++ specific test for this extension.

We might be doing it wrong for other adaptors, in which case we should also fix them, but not in this patch.

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/end.pass.cpp
91

Should we be using the new facilities with meta::for_each here? (everywhere)

libcxx/test/support/test_iterators.h
1022

Any reason why this is not constexpr when it can be? (everywhere)

This revision now requires changes to proceed.Dec 1 2022, 9:23 AM
var-const added inline comments.Dec 2 2022, 3:02 PM
libcxx/include/__ranges/as_rvalue_view.h
4

Please update the <ranges> synopsis as well.

31

This needs an include (probably currently relying on the transitive include from all.h).

111–115

I think this (an optimization, essentially) deserves a comment.

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/adaptor.pass.cpp
25

I think this check would be better in test_iterators.h, right after the definition of rvalue_iterator.

45

Can you also check piping a container (i.e. something that is not a view) through as_rvalue? Ideally, both lvalue and rvalue.

49

Nit: can you add empty lines between the cases? (Here and in some other tests)

53

s/auto/decltype(auto)/ (throughout).

56

The argument order is swapped in the comment.

74

Nit: return 0;.

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/begin.pass.cpp
30

These checks don't seem to be exhaustive. For example, there should probably be a check that !HasBegin if !range<const _View>.

33

This only tests the non-const version of begin, right? I think it shouldn't be too hard to also test a const as_rvalue_view here.

43

Optional: I think you could wrap this call in a check like if constexpr (std::sentinel_for<Iter, Iter>) and avoid having to call test_range directly from test.

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/end.pass.cpp
59

s/Begin/End/.

62

Can you also test the case where the concept is false?

71

Is it possible to just use the std::ranges::common_range concept?

74

Same as the begin tests -- I think this should also test when a view is const.

81

Same as the begin test -- I think this can be simplified with if constexpr.

99

Why are we checking begin here?

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/size.pass.cpp
54

Doesn't seem to be checked. Also, why is it only on the const sized view and not the non-const one?

57

Why is the return value only checked for the const case?

var-const requested changes to this revision.Dec 2 2022, 3:03 PM
huixie90 added inline comments.Dec 3 2022, 1:23 PM
libcxx/include/__ranges/as_rvalue_view.h
35–37

do we have a test for this?

39

do we have a test for this? and a test for explicit?

philnik updated this revision to Diff 487170.Sun, Jan 8, 5:25 AM
philnik marked 28 inline comments as done.

Address comments

libcxx/include/__ranges/as_rvalue_view.h
111–115

I'm not sure what you mean? This is required by the standard.

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/end.pass.cpp
71

Yes, but I'd rather avoid the meta-programming and just pass where it's expected to be a common range.

var-const accepted this revision as: var-const.Mon, Jan 9, 3:29 PM

LGTM (with just a couple of minor comments). I'll leave final approval to @ldionne since he had comments as well.

libcxx/include/__ranges/as_rvalue_view.h
111–115

We can still add a comment, even if this is essentially copied from the Standard. If I'm reading this correctly, this avoids wrapping a range in an rvalue_view if it's already a range of rvalues, to avoid unnecessary bloat. If that's correct, I think it deserves a comment.

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/ctor.pass.cpp
39

Would std::is_convertible work?

philnik updated this revision to Diff 489669.Mon, Jan 16, 6:44 PM

Address comments

philnik marked an inline comment as done.Mon, Jan 16, 6:46 PM
philnik added inline comments.
libcxx/include/__ranges/as_rvalue_view.h
111–115

AFAIK lots of views do this, and we don't comment anywhere else. Adding a comment here makes it look like this is an extension.

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/ctor.pass.cpp
39

Not for the default constructible case.

ldionne accepted this revision.Thu, Jan 19, 8:38 AM
ldionne added inline comments.
libcxx/include/__iterator/move_sentinel.h
53

I don't think this was addressed. Please try to ensure that you've addressed feedback before marking a comment as done, otherwise it's really easy to drop (potentially important) comments on the floor. Reviewers usually assume that the feedback has been implemented correctly when the comment is marked as done.

libcxx/include/__ranges/as_rvalue_view.h
111–115

I would agree that no comment is needed since this is indeed what the standard specifies. I'm actually not sure what the comment would say.

This revision is now accepted and ready to land.Thu, Jan 19, 8:38 AM
philnik updated this revision to Diff 490617.Thu, Jan 19, 11:36 AM
philnik marked an inline comment as done.

Try to fix CI

philnik updated this revision to Diff 490641.Thu, Jan 19, 1:07 PM
philnik marked 3 inline comments as done.
  • Try to fix CI
  • Address comments
This revision was landed with ongoing or failed builds.Thu, Jan 19, 9:00 PM
This revision was automatically updated to reflect the committed changes.