Skip to content

Commit 266f123

Browse files
committed
[libcxx] const_iterator and c{r,}{begin,end}
Papers: - [P2278R4][]: `cbegin` should always return a constant iterator - [P2836R1][]: `std::basic_const_iterator` should follow its underlying type's convertibility Issues: - [LWG3765][]: `const_sentinel` should be constrained - [LWG3766][]: `view_interface::cbegin` is underconstrained - [LWG3770][]: `const_sentinel_t` is missing - [LWG3769][]: `basic_const_iterator::operator==` causes infinite constraint recursion - [LWG3853][]: `basic_const_iterator<volatile int*>::operator->` is ill-formed - [LWG3862][]: `basic_const_iterator`'s `common_type` specialization is underconstrained - [LWG3872][]: `basic_const_iterator` should have custom `iter_move` - [LWG3946][]: The definition of `const_iterator_t` should be reworked - [LWG3948][]: _`possibly-const-range`_ and _`as-const-pointer`_ should be `noexcept` 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 [LWG3765]: https://wg21.link/lwg3765 [LWG3766]: https://wg21.link/lwg3766 [LWG3770]: https://wg21.link/lwg3770 [LWG3769]: https://wg21.link/lwg3769 [LWG3853]: https://wg21.link/lwg3853 [LWG3862]: https://wg21.link/lwg3862 [LWG3872]: https://wg21.link/lwg3872 [LWG3946]: https://wg21.link/lwg3946 [LWG3948]: https://wg21.link/lwg3948
1 parent a9c71d3 commit 266f123

34 files changed

+1836
-464
lines changed

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@
219219
"`LWG3761 <https://wg21.link/LWG3761>`__","``cartesian_product_view::iterator::operator-`` should pass by reference","2022-11 (Kona)","","",""
220220
"`LWG3762 <https://wg21.link/LWG3762>`__","``generator::iterator::operator==`` should pass by reference","2022-11 (Kona)","","",""
221221
"`LWG3764 <https://wg21.link/LWG3764>`__","``reference_wrapper::operator()`` should propagate noexcept","2022-11 (Kona)","|Complete|","17.0",""
222-
"`LWG3765 <https://wg21.link/LWG3765>`__","``const_sentinel`` should be constrained","2022-11 (Kona)","","",""
223-
"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","2022-11 (Kona)","","",""
224-
"`LWG3770 <https://wg21.link/LWG3770>`__","``const_sentinel_t`` is missing","2022-11 (Kona)","","",""
222+
"`LWG3765 <https://wg21.link/LWG3765>`__","``const_sentinel`` should be constrained","2022-11 (Kona)","|Complete|","20.0",""
223+
"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","2022-11 (Kona)","|Complete|","20.0",""
224+
"`LWG3770 <https://wg21.link/LWG3770>`__","``const_sentinel_t`` is missing","2022-11 (Kona)","|Complete|","20.0",""
225225
"`LWG3773 <https://wg21.link/LWG3773>`__","``views::zip_transform`` still requires ``F`` to be ``copy_constructible`` when empty pack","2022-11 (Kona)","","",""
226226
"`LWG3774 <https://wg21.link/LWG3774>`__","``<flat_set>`` should include ``<compare>``","2022-11 (Kona)","","",""
227227
"`LWG3775 <https://wg21.link/LWG3775>`__","Broken dependencies in the ``Cpp17Allocator`` requirements","2022-11 (Kona)","","",""
@@ -252,7 +252,7 @@
252252
"`LWG3664 <https://wg21.link/LWG3664>`__","`LWG 3392 <https://wg21.link/LWG3392>`__ ``broke std::ranges::distance(a, a+3)``","2023-02 (Issaquah)","","",""
253253
"`LWG3720 <https://wg21.link/LWG3720>`__","Restrict the valid types of ``arg-id`` for width and precision in ``std-format-spec``","2023-02 (Issaquah)","|Complete|","17.0",""
254254
"`LWG3756 <https://wg21.link/LWG3756>`__","Is the ``std::atomic_flag`` class signal-safe?","2023-02 (Issaquah)","","",""
255-
"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","2023-02 (Issaquah)","","",""
255+
"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","2023-02 (Issaquah)","|Complete|","20.0",""
256256
"`LWG3807 <https://wg21.link/LWG3807>`__","The feature test macro for ``ranges::find_last`` should be renamed","2023-02 (Issaquah)","","",""
257257
"`LWG3811 <https://wg21.link/LWG3811>`__","``views::as_const`` on ``ref_view<T>`` should return ``ref_view<const T>``","2023-02 (Issaquah)","","",""
258258
"`LWG3820 <https://wg21.link/LWG3820>`__","``cartesian_product_view::iterator::prev`` is not quite right","2023-02 (Issaquah)","","",""
@@ -271,7 +271,7 @@
271271
"`LWG3849 <https://wg21.link/LWG3849>`__","``cartesian_product_view::iterator``'s default constructor is overconstrained","2023-02 (Issaquah)","","",""
272272
"`LWG3850 <https://wg21.link/LWG3850>`__","``views::as_const`` on ``empty_view<T>`` should return ``empty_view<const T>``","2023-02 (Issaquah)","","",""
273273
"`LWG3851 <https://wg21.link/LWG3851>`__","``chunk_view::inner-iterator`` missing custom ``iter_move`` and ``iter_swap``","2023-02 (Issaquah)","","",""
274-
"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","2023-02 (Issaquah)","","",""
274+
"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","2023-02 (Issaquah)","|Complete|","20.0",""
275275
"`LWG3857 <https://wg21.link/LWG3857>`__","``basic_string_view`` should allow explicit conversion when only traits vary","2023-02 (Issaquah)","|Complete|","17.0",""
276276
"`LWG3860 <https://wg21.link/LWG3860>`__","``range_common_reference_t`` is missing","2023-02 (Issaquah)","|Complete|","17.0",""
277277
"`LWG3866 <https://wg21.link/LWG3866>`__","Bad Mandates for ``expected::transform_error`` overloads","2023-02 (Issaquah)","|Complete|","17.0",""
@@ -293,12 +293,12 @@
293293
"`LWG3836 <https://wg21.link/LWG3836>`__","``std::expected<bool, E1>`` conversion constructor ``expected(const expected<U, G>&)`` should take precedence over ``expected(U&&)`` with operator ``bool``","2023-02 (Issaquah)","|Complete|","18.0",""
294294
"`LWG3843 <https://wg21.link/LWG3843>`__","``std::expected<T,E>::value() &`` assumes ``E`` is copy constructible","2023-02 (Issaquah)","|Complete|","17.0",""
295295
"`LWG3847 <https://wg21.link/LWG3847>`__","``ranges::to`` can still return views","2023-02 (Issaquah)","|Complete|","17.0",""
296-
"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","2023-02 (Issaquah)","","",""
296+
"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","2023-02 (Issaquah)","|Complete|","20.0",""
297297
"`LWG3865 <https://wg21.link/LWG3865>`__","Sorting a range of ``pairs``","2023-02 (Issaquah)","|Complete|","17.0",""
298298
"`LWG3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","2023-02 (Issaquah)","|Complete|","19.0",""
299299
"`LWG3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","2023-02 (Issaquah)","","",""
300300
"`LWG3871 <https://wg21.link/LWG3871>`__","Adjust note about ``terminate``","2023-02 (Issaquah)","","",""
301-
"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","2023-02 (Issaquah)","","",""
301+
"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","2023-02 (Issaquah)","|Complete|","20.0",""
302302
"`LWG3875 <https://wg21.link/LWG3875>`__","``std::ranges::repeat_view<T, IntegerClass>::iterator`` may be ill-formed","2023-02 (Issaquah)","|Complete|","17.0",""
303303
"`LWG3876 <https://wg21.link/LWG3876>`__","Default constructor of ``std::layout_XX::mapping`` misses precondition","2023-02 (Issaquah)","","",""
304304
"`LWG3877 <https://wg21.link/LWG3877>`__","Incorrect constraints on ``const``-qualified monadic overloads for ``std::expected``","2023-02 (Issaquah)","|Complete|","17.0",""

libcxx/docs/Status/Cxx23Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"`P1899R3 <https://wg21.link/P1899R3>`__","``stride_view``","2022-07 (Virtual)","","",""
6262
"`P2093R14 <https://wg21.link/P2093R14>`__","Formatted output","2022-07 (Virtual)","|Complete|","18.0",""
6363
"`P2165R4 <https://wg21.link/P2165R4>`__","Compatibility between ``tuple``, ``pair`` and ``tuple-like`` objects","2022-07 (Virtual)","","",""
64-
"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","2022-07 (Virtual)","","",""
64+
"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","2022-07 (Virtual)","|In Progress|","20.0","``basic_const_iterator`` and the changes to the const range access functions (less ``cdata``) are implemented."
6565
"`P2286R8 <https://wg21.link/P2286R8>`__","Formatting Ranges","2022-07 (Virtual)","|Complete|","16.0",""
6666
"`P2291R3 <https://wg21.link/P2291R3>`__","Add Constexpr Modifiers to Functions ``to_chars`` and ``from_chars`` for Integral Types in ``<charconv>`` Header","2022-07 (Virtual)","|Complete|","16.0",""
6767
"`P2302R4 <https://wg21.link/P2302R4>`__","``std::ranges::contains``","2022-07 (Virtual)","|Complete|","19.0",""

libcxx/docs/Status/Cxx2cIssues.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"`LWG3809 <https://wg21.link/LWG3809>`__","Is ``std::subtract_with_carry_engine<uint16_t>`` supposed to work","2023-11 (Kona)","","",""
2626
"`LWG3892 <https://wg21.link/LWG3892>`__","Incorrect formatting of nested ranges and tuples","2023-11 (Kona)","|Complete|","17.0",""
2727
"`LWG3897 <https://wg21.link/LWG3897>`__","``inout_ptr`` will not update raw pointer to 0","2023-11 (Kona)","|Complete|","19.0",""
28-
"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","2023-11 (Kona)","","",""
28+
"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","2023-11 (Kona)","|Complete|","20.0",""
2929
"`LWG3947 <https://wg21.link/LWG3947>`__","Unexpected constraints on ``adjacent_transform_view::base()``","2023-11 (Kona)","","",""
30-
"`LWG3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","2023-11 (Kona)","","",""
30+
"`LWG3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","2023-11 (Kona)","|In Progress|","20.0","Implemented for _``possibly-const-range``_, since _``as-const-pointer``_ is not yet implemented."
3131
"`LWG3949 <https://wg21.link/LWG3949>`__","``std::atomic<bool>``'s trivial destructor dropped in C++17 spec wording","2023-11 (Kona)","","",""
3232
"`LWG3951 <https://wg21.link/LWG3951>`__","[expected.object.swap]: Using ``value()`` instead of ``has_value()``","2023-11 (Kona)","|Complete|","16.0",""
3333
"`LWG3953 <https://wg21.link/LWG3953>`__","``iter_move`` for ``common_iterator`` and ``counted_iterator`` should return ``decltype(auto)``","2023-11 (Kona)","","",""

libcxx/docs/Status/Cxx2cPapers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"`P2819R2 <https://wg21.link/P2819R2>`__","Add tuple protocol to complex","2023-11 (Kona)","|Complete|","19.0",""
4343
"`P2937R0 <https://wg21.link/P2937R0>`__","Freestanding: Remove ``strtok``","2023-11 (Kona)","","",""
4444
"`P2833R2 <https://wg21.link/P2833R2>`__","Freestanding Library: inout expected span","2023-11 (Kona)","","",""
45-
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","","",""
45+
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","|Complete|","20.0","Implemented as a DR against C++23. (MSVC STL and libstdc++ will do the same.)"
4646
"`P2264R7 <https://wg21.link/P2264R7>`__","Make ``assert()`` macro user friendly for C and C++","2023-11 (Kona)","","",""
4747
"`P1673R13 <https://wg21.link/P1673R13>`__","A free function linear algebra interface based on the BLAS","2023-11 (Kona)","","",""
4848
"","","","","",""

libcxx/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ set(files
444444
__iterator/bounded_iter.h
445445
__iterator/common_iterator.h
446446
__iterator/concepts.h
447+
__iterator/const_iterator.h
447448
__iterator/counted_iterator.h
448449
__iterator/cpp17_iterator_concepts.h
449450
__iterator/data.h
@@ -639,6 +640,7 @@ set(files
639640
__ranges/chunk_by_view.h
640641
__ranges/common_view.h
641642
__ranges/concepts.h
643+
__ranges/const_access.h
642644
__ranges/container_compatible_range.h
643645
__ranges/counted.h
644646
__ranges/dangling.h

libcxx/include/__algorithm/ranges_reverse_copy.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3434

3535
namespace ranges {
3636

37+
template <ranges::bidirectional_range _Range>
38+
_LIBCPP_HIDE_FROM_ABI constexpr ranges::subrange<reverse_iterator<ranges::iterator_t<_Range>>,
39+
reverse_iterator<ranges::iterator_t<_Range>>>
40+
__reverse_range(_Range&& __range) {
41+
auto __first = ranges::begin(__range);
42+
return {std::make_reverse_iterator(ranges::next(__first, ranges::end(__range))), std::make_reverse_iterator(__first)};
43+
}
44+
3745
template <class _InIter, class _OutIter>
3846
using reverse_copy_result = in_out_result<_InIter, _OutIter>;
3947

@@ -49,7 +57,7 @@ struct __reverse_copy {
4957
requires indirectly_copyable<iterator_t<_Range>, _OutIter>
5058
_LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result<borrowed_iterator_t<_Range>, _OutIter>
5159
operator()(_Range&& __range, _OutIter __result) const {
52-
auto __ret = ranges::copy(std::__reverse_range(__range), std::move(__result));
60+
auto __ret = ranges::copy(std::ranges::__reverse_range(__range), std::move(__result));
5361
return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)};
5462
}
5563
};

0 commit comments

Comments
 (0)