Skip to content

P2415 What Is A view? - #2275

Merged
Stephan T. Lavavej (StephanTLavavej) merged 7 commits into
microsoft:mainfrom
CaseyCarter:p2415
Nov 13, 2021
Merged

Stephan T. Lavavej (StephanTLavavej) merged 7 commits into
microsoft:mainfrom
CaseyCarter:p2415

Conversation

@CaseyCarter

Copy link
Copy Markdown
Contributor

Add the move-only range adaptor owning_view, and use it to implement views::all changes to correspond with viewable_range changes.

Resolves #2238

Add the move-only range adaptor `owning_view`, and use it to implement `views::all` changes to correspond with `viewable_range` changes.

Resolves microsoft#2238
@CaseyCarter Casey Carter (CaseyCarter) added high priority Important! ranges C++20/23 ranges defect report Applied retroactively labels Oct 13, 2021
@CaseyCarter
Casey Carter (CaseyCarter) requested a review from a team as a code owner October 13, 2021 09:50
Comment thread stl/inc/ranges
Comment thread stl/inc/ranges Outdated
Comment thread stl/inc/ranges Outdated

// clang-format off
template
requires (movable<_Rng> && !_Is_specialization_v, initializer_list>)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we could put that into a named concept

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On first read I misinterpreted this as a request to put _Is_specialization_v, initializer_list> into an _Is_initializer_list helper so this would more closely reflect the wording from the working draft. This makes a ton of sense to me.

Your comment on 1527, however, implies that you want the entire requires-clause (and presumably the type-constraint as well) pulled out into a helper concept. I'm inclined not to do so, again because I'd like the wording to more closely reflect the working draft. Do you have a motivating concern?

Comment thread stl/inc/ranges Outdated
Comment thread tests/std/tests/P2415R2_owning_view/test.cpp Outdated
Comment thread stl/inc/ranges Outdated
Comment thread stl/inc/ranges Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grain of salt: the paper has not yet been available

@CaseyCarter

Copy link
Copy Markdown
Contributor Author

Grain of salt: the paper has not yet been available

P2415R2.zip (Zipped because GitHub refuses .html attachments 🤷)

@miscco

Copy link
Copy Markdown
Contributor

Grain of salt: the paper has not yet been available

P2415R2.zip (Zipped because GitHub refuses .html attachments 🤷)

Thanks, I am not salty any more

Comment thread tests/std/tests/P2415R2_owning_view/test.cpp
Comment thread tests/std/tests/P2415R2_owning_view/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_views_drop/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_views_drop/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_views_elements/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_views_join/test.cpp Outdated
Comment thread tests/std/tests/P0896R4_views_reverse/test.cpp Outdated
@StephanTLavavej

This comment has been minimized.

Comment thread stl/inc/ranges
return _RANGES empty(_Range);
}
_NODISCARD constexpr bool empty() const noexcept(noexcept(_RANGES empty(_Range))) /* strengthened */
requires _Can_empty {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we write the requires requires constraint directly? or does that need requires expression support that we don't have?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view_interface has four occurrences of this same ad-hoc constraint, so I made a helper concept for DRY purposes. Michael Schellenberger Costa (@miscco) implemented ref_view very shortly thereafter and reused the helper, I assume also just for DRY. I copy-pasted ref_view to make owning_view and didn't give this constraint any thought at all.

TLDR: Everybody hates requires requires. Shout if you'd prefer that we spell it out explicitly here (and/or elsewhere) so as to more obviously agree with the Standard wording. Both are equivalent under as-if.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the named concept.

Comment thread tests/std/tests/P0896R4_views_take_while/test.cpp
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 8451694 into microsoft:main Nov 13, 2021
@StephanTLavavej

Copy link
Copy Markdown
Member

2 years after C++20 was published, I'm glad we've finally found the answer to what a view is! 😹 👁️ 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx20 C++20 feature defect report Applied retroactively ranges C++20/23 ranges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2415R2 What Is A view?

4 participants