Skip to content

[libc++] The rest of P2278R4 (cdata, as_const_view, span changes) #102301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from

Conversation

strega-nil
Copy link
Contributor

@strega-nil strega-nil commented Aug 7, 2024

This PR depends on, and is committed on top of, LLVM-PR-99915.

This PR completes the rest of P2278R4 that was not done in the original PR:

Actual changes (excluding those from LLVM-PR-99915): diff 99915.

  • cdata
  • Changes to span (includes some interesting choices since const_iterator cannot support volatile element types)
  • as_const_view and views::as_const
  • The __cpp_lib_ranges_as_const feature macro

Copy link

github-actions bot commented Aug 7, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Comment on lines +133 to +135
__empty_view,
__span,
__ref_view,
Copy link
Contributor

Choose a reason for hiding this comment

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

LWG3811 and LWG3850 are completed here and thus the entries should be updated:

"`LWG3811 <https://wg21.link/LWG3811>`__","``views::as_const`` on ``ref_view<T>`` should return ``ref_view<const T>``","February 2023","","","|ranges|"

"`LWG3850 <https://wg21.link/LWG3850>`__","``views::as_const`` on ``empty_view<T>`` should return ``empty_view<const T>``","February 2023","","","|ranges|"

struct __fn {
# if _LIBCPP_STD_VER >= 23
template <class _Tp>
_LIBCPP_HIDE_FROM_ABI constexpr static auto __as_const_pointer(const _Tp* __ptr) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto for LWG3948 (assuming the #99915 will be merged first):

"`LWG3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","Kona November 2023","","","|ranges|"

Papers: [P2278R4][], [P2836R1][]
PR: [LLVM-PR-99915][]

Implements:

- `basic_const_iterator`, `const_iterator`, and `const_sentinel`
- The const accessors - `ranges::{cbegin,cend,crbegin,crend}`
- Add `cbegin` and `cend` member functions to `view_interface`
- The changes from [P2836R1][].

Still to be done:
- `ranges::as_const_view`, `ranges::views::as_const`
- `cdata`
- The changes to `span`

Drive-by:
- Fix some includes that would have been circular.

[P2278R4]: https://wg21.link/p2278r4
[P2836R1]: https://wg21.link/p2836r1
[LLVM-PR-99915]: llvm#99915
drive-by: remove the `__ranges/data.h` header and merge it with
`__ranges/access.h` (for `ranges::data`), or `__ranges/const_access.h`
(for `ranges::cdata`). I felt comfortable doing this as every use of
`__ranges/access.h` included either `__ranges/data.h` itself, or
`__ranges/concepts.h` which itself included `__ranges/data.h`.
Note that we have an interesting extension in `span` to support volatile
types - this breaks `std::const_iterator`.

I've made the choice to, when `span`'s element type is `volatile`,
set `const_iterator` and `const_reverse_iterator` to `void`,
and disable `cbegin` and friends.
I wonder if it would be a good idea to do something more similar to what
MSVC does here, with `_Choice` stuff.
@strega-nil
Copy link
Contributor Author

Closing as this will be merged into the original PR.

@strega-nil strega-nil closed this Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants