Skip to content

Commit 913d2ea

Browse files
committed
[libcxx] const_iterator and c{r,}{begin,end}
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
1 parent 388b632 commit 913d2ea

36 files changed

+1834
-461
lines changed

libcxx/docs/Status/Cxx23.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Paper Status
4343
.. [#note-P0533R9] P0533R9: ``isfinite``, ``isinf``, ``isnan`` and ``isnormal`` are implemented.
4444
.. [#note-P1413R3] P1413R3: ``std::aligned_storage_t`` and ``std::aligned_union_t`` are marked deprecated, but
4545
clang doesn't issue a diagnostic for deprecated using template declarations.
46+
.. [#note-P2278R4] P2278R4: ``basic_const_iterator`` has been implemented, and the const range accessors
47+
(``cbegin``, ``cend``, ``crbegin``, ``crend``) have been updated to return this new type.
48+
However, the changes to ``cdata`` and ``span``, and ``const_view``, have not yet been implemented.
4649
.. [#note-P2520R0] P2520R0: Libc++ implemented this paper as a DR in C++20 as well.
4750
.. [#note-P2711R1] P2711R1: ``join_with_view`` hasn't been done yet since this type isn't implemented yet.
4851
.. [#note-P2770R0] P2770R0: ``join_with_view`` hasn't been done yet since this type isn't implemented yet.

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
"`LWG3762 <https://wg21.link/LWG3762>`__","``generator::iterator::operator==`` should pass by reference","November 2022","","",""
221221
"`LWG3764 <https://wg21.link/LWG3764>`__","``reference_wrapper::operator()`` should propagate noexcept","November 2022","|Complete|","17.0",""
222222
"`LWG3765 <https://wg21.link/LWG3765>`__","``const_sentinel`` should be constrained","November 2022","","","|ranges|"
223-
"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","November 2022","","","|ranges|"
223+
"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","November 2022","|Complete|","20.0","|ranges|"
224224
"`LWG3770 <https://wg21.link/LWG3770>`__","``const_sentinel_t`` is missing","November 2022","","","|ranges|"
225225
"`LWG3773 <https://wg21.link/LWG3773>`__","``views::zip_transform`` still requires ``F`` to be ``copy_constructible`` when empty pack","November 2022","","","|ranges|"
226226
"`LWG3774 <https://wg21.link/LWG3774>`__","``<flat_set>`` should include ``<compare>``","November 2022","","","|flat_containers|"
@@ -252,7 +252,7 @@
252252
"`LWG3664 <https://wg21.link/LWG3664>`__","`LWG 3392 <https://wg21.link/LWG3392>`__ ``broke std::ranges::distance(a, a+3)``","February 2023","","","|ranges|"
253253
"`LWG3720 <https://wg21.link/LWG3720>`__","Restrict the valid types of ``arg-id`` for width and precision in ``std-format-spec``","February 2023","|Complete|","17.0","|format|"
254254
"`LWG3756 <https://wg21.link/LWG3756>`__","Is the ``std::atomic_flag`` class signal-safe?","February 2023","","",""
255-
"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","February 2023","","","|spaceship|"
255+
"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","February 2023","|Complete|","20.0","|spaceship|"
256256
"`LWG3807 <https://wg21.link/LWG3807>`__","The feature test macro for ``ranges::find_last`` should be renamed","February 2023","","","|ranges|"
257257
"`LWG3811 <https://wg21.link/LWG3811>`__","``views::as_const`` on ``ref_view<T>`` should return ``ref_view<const T>``","February 2023","","","|ranges|"
258258
"`LWG3820 <https://wg21.link/LWG3820>`__","``cartesian_product_view::iterator::prev`` is not quite right","February 2023","","","|ranges|"
@@ -271,7 +271,7 @@
271271
"`LWG3849 <https://wg21.link/LWG3849>`__","``cartesian_product_view::iterator``'s default constructor is overconstrained","February 2023","","","|ranges|"
272272
"`LWG3850 <https://wg21.link/LWG3850>`__","``views::as_const`` on ``empty_view<T>`` should return ``empty_view<const T>``","February 2023","","","|ranges|"
273273
"`LWG3851 <https://wg21.link/LWG3851>`__","``chunk_view::inner-iterator`` missing custom ``iter_move`` and ``iter_swap``","February 2023","","","|ranges|"
274-
"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","February 2023","","",""
274+
"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","February 2023","|Complete|","20.0",""
275275
"`LWG3857 <https://wg21.link/LWG3857>`__","``basic_string_view`` should allow explicit conversion when only traits vary","February 2023","|Complete|","17.0",""
276276
"`LWG3860 <https://wg21.link/LWG3860>`__","``range_common_reference_t`` is missing","February 2023","|Complete|","17.0","|ranges|"
277277
"`LWG3866 <https://wg21.link/LWG3866>`__","Bad Mandates for ``expected::transform_error`` overloads","February 2023","|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``","February 2023","|Complete|","18.0",""
294294
"`LWG3843 <https://wg21.link/LWG3843>`__","``std::expected<T,E>::value() &`` assumes ``E`` is copy constructible","February 2023","|Complete|","17.0",""
295295
"`LWG3847 <https://wg21.link/LWG3847>`__","``ranges::to`` can still return views","February 2023","|Complete|","17.0","|ranges|"
296-
"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","February 2023","","",""
296+
"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","February 2023","|Complete|","20.0",""
297297
"`LWG3865 <https://wg21.link/LWG3865>`__","Sorting a range of ``pairs``","February 2023","|Complete|","17.0","|ranges|"
298298
"`LWG3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","February 2023","|Complete|","19.0",""
299299
"`LWG3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","February 2023","","",""
300300
"`LWG3871 <https://wg21.link/LWG3871>`__","Adjust note about ``terminate``","February 2023","","",""
301-
"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","February 2023","","",""
301+
"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","February 2023","|Complete|","20.0",""
302302
"`LWG3875 <https://wg21.link/LWG3875>`__","``std::ranges::repeat_view<T, IntegerClass>::iterator`` may be ill-formed","February 2023","|Complete|","17.0","|ranges|"
303303
"`LWG3876 <https://wg21.link/LWG3876>`__","Default constructor of ``std::layout_XX::mapping`` misses precondition","February 2023","","",""
304304
"`LWG3877 <https://wg21.link/LWG3877>`__","Incorrect constraints on ``const``-qualified monadic overloads for ``std::expected``","February 2023","|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``","July 2022","","","|ranges|"
6262
"`P2093R14 <https://wg21.link/P2093R14>`__","Formatted output","July 2022","|Complete|","18.0","|format|"
6363
"`P2165R4 <https://wg21.link/P2165R4>`__","Compatibility between ``tuple``, ``pair`` and ``tuple-like`` objects","July 2022","","",""
64-
"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","July 2022","","","|ranges|"
64+
"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","July 2022","|In progress| [#note-P2278R4]","","|ranges|"
6565
"`P2286R8 <https://wg21.link/P2286R8>`__","Formatting Ranges","July 2022","|Complete|","16.0","|format| |ranges|"
6666
"`P2291R3 <https://wg21.link/P2291R3>`__","Add Constexpr Modifiers to Functions ``to_chars`` and ``from_chars`` for Integral Types in ``<charconv>`` Header","July 2022","|Complete|","16.0",""
6767
"`P2302R4 <https://wg21.link/P2302R4>`__","``std::ranges::contains``","July 2022","|Complete|","19.0","|ranges|"

libcxx/docs/Status/Cxx2c.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Paper Status
4444
.. [#note-P2944R3] Implemented comparisons for ``reference_wrapper`` only.
4545
.. [#note-P2422R1] Libc++ keeps the ``nodiscard`` attributes as a conforming extension.
4646
.. [#note-P2997R1] This paper is applied as DR against C++20. (MSVC STL and libstdc++ will do the same.)
47+
.. [#note-P2836R1] This paper is applies as DR against C++23 (MSVC STL and libstdc++ have done the same);
48+
The feature macro is not yet defined, since other features from the original paper have not been completed.
4749
4850
.. _issues-status-cxx2c:
4951

libcxx/docs/Status/Cxx2cIssues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"`LWG3809 <https://wg21.link/LWG3809>`__","Is ``std::subtract_with_carry_engine<uint16_t>`` supposed to work","Kona November 2023","","",""
2626
"`LWG3892 <https://wg21.link/LWG3892>`__","Incorrect formatting of nested ranges and tuples","Kona November 2023","|Complete|","17.0","|format|"
2727
"`LWG3897 <https://wg21.link/LWG3897>`__","``inout_ptr`` will not update raw pointer to 0","Kona November 2023","|Complete|","19.0",""
28-
"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","Kona November 2023","","",""
28+
"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","Kona November 2023","|Complete|","20.0",""
2929
"`LWG3947 <https://wg21.link/LWG3947>`__","Unexpected constraints on ``adjacent_transform_view::base()``","Kona November 2023","","","|ranges|"
3030
"`LWG3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","Kona November 2023","","","|ranges|"
3131
"`LWG3949 <https://wg21.link/LWG3949>`__","``std::atomic<bool>``'s trivial destructor dropped in C++17 spec wording","Kona November 2023","","",""

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","Kona November 2023","|Complete|","19.0",""
4343
"`P2937R0 <https://wg21.link/P2937R0>`__","Freestanding: Remove ``strtok``","Kona November 2023","","",""
4444
"`P2833R2 <https://wg21.link/P2833R2>`__","Freestanding Library: inout expected span","Kona November 2023","","",""
45-
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","Kona November 2023","","","|DR|"
45+
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","Kona November 2023","|Complete| [#note-P2836R1]","20.0","|DR|"
4646
"`P2264R7 <https://wg21.link/P2264R7>`__","Make ``assert()`` macro user friendly for C and C++","Kona November 2023","","",""
4747
"`P1673R13 <https://wg21.link/P1673R13>`__","A free function linear algebra interface based on the BLAS","Kona November 2023","","",""
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)