Skip to content

Commit 54f6a6e

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 54f6a6e

34 files changed

+1821
-455
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/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/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]","","|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)