Skip to content

[libcxx] cbegin should always return a constant iterator #99915

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

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5b9c2df
[libcxx] `cbegin` should always return a constant iterator
strega-nil Sep 2, 2024
f348b3c
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Oct 31, 2024
9c2f7ca
Remove a mistakenly merged line in `module.modulemap`
frederick-vs-ja Oct 31, 2024
2601e34
Missing inclusion and test skipping
frederick-vs-ja Nov 1, 2024
40e7a25
Transitive inclusions and forward declaration of `span`
frederick-vs-ja Nov 1, 2024
8b50c88
Missing inclusion of `<__ranges/enable_borrowed_range.h>`
frederick-vs-ja Nov 1, 2024
eaf5c51
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Nov 1, 2024
c1a350e
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Nov 2, 2024
5831f31
Clang-format `std/containers/views/views.span/types.pass.cpp`
frederick-vs-ja Mar 19, 2025
4c87db5
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Mar 19, 2025
9e28bd8
Semantic merging and release note
frederick-vs-ja Mar 19, 2025
f0fb6cc
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Mar 19, 2025
28ef669
Clang-format
frederick-vs-ja Mar 19, 2025
10ae9d0
Drop `ASSERT_RUNTIME_AND_CONSTEXPR`
frederick-vs-ja Mar 19, 2025
3283347
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Mar 19, 2025
466abe1
Fixes for `_LIBCPP_NODEBUG`, `std` module, and tests
frederick-vs-ja Mar 19, 2025
6575917
Fix `_LIBCPP_NODEBUG` again
frederick-vs-ja Mar 19, 2025
af76980
Implement LWG4027 `possibly-const-range` should prefer returning `con…
frederick-vs-ja Mar 19, 2025
0dad30e
Documentation for LWG4027
frederick-vs-ja Mar 19, 2025
d22a25d
Fixup for LWG4027
frederick-vs-ja Mar 19, 2025
930a9cb
Address some review comments
frederick-vs-ja Mar 21, 2025
9c498c7
Use `// REQUIRES: std-at-least-c++23` for some tests
frederick-vs-ja Mar 21, 2025
f59baeb
Inline `iterator_concept` into `basic_const_iterator`
frederick-vs-ja Mar 21, 2025
22f1dac
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Mar 21, 2025
5f9d8ff
Product code changes
frederick-vs-ja Mar 24, 2025
afbda54
Test explicitness of `as_const_view`'s functions
frederick-vs-ja Mar 25, 2025
1fd78c6
Test some properties of iterator operations
frederick-vs-ja Mar 25, 2025
bbe8e35
Test implicitness of `basic_const_iterator`'s constructor
frederick-vs-ja Mar 25, 2025
51c1006
Merge branch 'main' into P2278R4_cbegin
frederick-vs-ja Mar 25, 2025
dd9c7cd
Fixup
frederick-vs-ja Mar 25, 2025
3e932f4
Fixup again
frederick-vs-ja Mar 25, 2025
444f19f
Test constraints on `const_iterator`/`const_sentinel` (LWG3765)
frederick-vs-ja Mar 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_ranges`` ``202406L``
---------------------------------------------------------- -----------------
``__cpp_lib_ranges_as_const`` *unimplemented*
``__cpp_lib_ranges_as_const`` ``202311L``
---------------------------------------------------------- -----------------
``__cpp_lib_ranges_as_rvalue`` ``202207L``
---------------------------------------------------------- -----------------
Expand Down
2 changes: 2 additions & 0 deletions libcxx/docs/ReleaseNotes/21.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Implemented Papers
- P2255R2: A type trait to detect reference binding to temporary (implemented the type traits only) (`Github <https://github.com/llvm/llvm-project/issues/105180>`__)
- P2562R1: ``constexpr`` Stable Sorting (`Github <https://github.com/llvm/llvm-project/issues/105360>`__)
- P1222R4: A Standard ``flat_set`` is partially implemented and ``flat_set`` is provided (`Github <https://github.com/llvm/llvm-project/issues/105193>`__)
- P2278R4: ``cbegin`` should always return a constant iterator (`Github <https://github.com/llvm/llvm-project/issues/105201>`__)
- P2836R1: ``std::basic_const_iterator`` should follow its underlying type's convertibility (`Github <https://github.com/llvm/llvm-project/issues/105406>`__)

Improvements and New Features
-----------------------------
Expand Down
18 changes: 9 additions & 9 deletions libcxx/docs/Status/Cxx23Issues.csv
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@
"`LWG3761 <https://wg21.link/LWG3761>`__","``cartesian_product_view::iterator::operator-`` should pass by reference","2022-11 (Kona)","","",""
"`LWG3762 <https://wg21.link/LWG3762>`__","``generator::iterator::operator==`` should pass by reference","2022-11 (Kona)","","",""
"`LWG3764 <https://wg21.link/LWG3764>`__","``reference_wrapper::operator()`` should propagate noexcept","2022-11 (Kona)","|Complete|","17",""
"`LWG3765 <https://wg21.link/LWG3765>`__","``const_sentinel`` should be constrained","2022-11 (Kona)","","",""
"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","2022-11 (Kona)","","",""
"`LWG3770 <https://wg21.link/LWG3770>`__","``const_sentinel_t`` is missing","2022-11 (Kona)","","",""
"`LWG3765 <https://wg21.link/LWG3765>`__","``const_sentinel`` should be constrained","2022-11 (Kona)","|Complete|","21",""
"`LWG3766 <https://wg21.link/LWG3766>`__","``view_interface::cbegin`` is underconstrained","2022-11 (Kona)","|Complete|","21",""
"`LWG3770 <https://wg21.link/LWG3770>`__","``const_sentinel_t`` is missing","2022-11 (Kona)","|Complete|","21",""
"`LWG3773 <https://wg21.link/LWG3773>`__","``views::zip_transform`` still requires ``F`` to be ``copy_constructible`` when empty pack","2022-11 (Kona)","","",""
"`LWG3774 <https://wg21.link/LWG3774>`__","``<flat_set>`` should include ``<compare>``","2022-11 (Kona)","","",""
"`LWG3775 <https://wg21.link/LWG3775>`__","Broken dependencies in the ``Cpp17Allocator`` requirements","2022-11 (Kona)","","",""
Expand Down Expand Up @@ -252,9 +252,9 @@
"`LWG3664 <https://wg21.link/LWG3664>`__","`LWG 3392 <https://wg21.link/LWG3392>`__ ``broke std::ranges::distance(a, a+3)``","2023-02 (Issaquah)","","",""
"`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",""
"`LWG3756 <https://wg21.link/LWG3756>`__","Is the ``std::atomic_flag`` class signal-safe?","2023-02 (Issaquah)","","",""
"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","2023-02 (Issaquah)","","",""
"`LWG3769 <https://wg21.link/LWG3769>`__","``basic_const_iterator::operator==`` causes infinite constraint recursion","2023-02 (Issaquah)","|Complete|","21",""
"`LWG3807 <https://wg21.link/LWG3807>`__","The feature test macro for ``ranges::find_last`` should be renamed","2023-02 (Issaquah)","","",""
"`LWG3811 <https://wg21.link/LWG3811>`__","``views::as_const`` on ``ref_view<T>`` should return ``ref_view<const T>``","2023-02 (Issaquah)","","",""
"`LWG3811 <https://wg21.link/LWG3811>`__","``views::as_const`` on ``ref_view<T>`` should return ``ref_view<const T>``","2023-02 (Issaquah)","|Complete|","21",""
"`LWG3820 <https://wg21.link/LWG3820>`__","``cartesian_product_view::iterator::prev`` is not quite right","2023-02 (Issaquah)","","",""
"`LWG3825 <https://wg21.link/LWG3825>`__","Missing compile-time argument ``id`` check in ``basic_format_parse_context::next_arg_id``","2023-02 (Issaquah)","|Complete|","17",""
"`LWG3204 <https://wg21.link/LWG3204>`__","``sub_match::swap`` only swaps the base class","2023-02 (Issaquah)","|Complete|","17",""
Expand All @@ -269,9 +269,9 @@
"`LWG3842 <https://wg21.link/LWG3842>`__","Unclear wording for ``precision`` in ``chrono-format-spec``","2023-02 (Issaquah)","|Complete|","16",""
"`LWG3848 <https://wg21.link/LWG3848>`__","``adjacent_view``, ``adjacent_transform_view`` and ``slide_view`` missing ``base`` accessor","2023-02 (Issaquah)","","",""
"`LWG3849 <https://wg21.link/LWG3849>`__","``cartesian_product_view::iterator``'s default constructor is overconstrained","2023-02 (Issaquah)","","",""
"`LWG3850 <https://wg21.link/LWG3850>`__","``views::as_const`` on ``empty_view<T>`` should return ``empty_view<const T>``","2023-02 (Issaquah)","","",""
"`LWG3850 <https://wg21.link/LWG3850>`__","``views::as_const`` on ``empty_view<T>`` should return ``empty_view<const T>``","2023-02 (Issaquah)","|Complete|","21",""
"`LWG3851 <https://wg21.link/LWG3851>`__","``chunk_view::inner-iterator`` missing custom ``iter_move`` and ``iter_swap``","2023-02 (Issaquah)","","",""
"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","2023-02 (Issaquah)","","",""
"`LWG3853 <https://wg21.link/LWG3853>`__","``basic_const_iterator<volatile int*>::operator->`` is ill-formed","2023-02 (Issaquah)","|Complete|","21",""
"`LWG3857 <https://wg21.link/LWG3857>`__","``basic_string_view`` should allow explicit conversion when only traits vary","2023-02 (Issaquah)","|Complete|","17",""
"`LWG3860 <https://wg21.link/LWG3860>`__","``range_common_reference_t`` is missing","2023-02 (Issaquah)","|Complete|","17",""
"`LWG3866 <https://wg21.link/LWG3866>`__","Bad Mandates for ``expected::transform_error`` overloads","2023-02 (Issaquah)","|Complete|","17",""
Expand All @@ -293,12 +293,12 @@
"`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",""
"`LWG3843 <https://wg21.link/LWG3843>`__","``std::expected<T,E>::value() &`` assumes ``E`` is copy constructible","2023-02 (Issaquah)","|Complete|","17",""
"`LWG3847 <https://wg21.link/LWG3847>`__","``ranges::to`` can still return views","2023-02 (Issaquah)","|Complete|","17",""
"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","2023-02 (Issaquah)","","",""
"`LWG3862 <https://wg21.link/LWG3862>`__","``basic_const_iterator``'s ``common_type`` specialization is underconstrained","2023-02 (Issaquah)","|Complete|","21",""
"`LWG3865 <https://wg21.link/LWG3865>`__","Sorting a range of ``pairs``","2023-02 (Issaquah)","|Complete|","17",""
"`LWG3869 <https://wg21.link/LWG3869>`__","Deprecate ``std::errc`` constants related to UNIX STREAMS","2023-02 (Issaquah)","|Complete|","19",""
"`LWG3870 <https://wg21.link/LWG3870>`__","Remove ``voidify``","2023-02 (Issaquah)","|Complete|","20",""
"`LWG3871 <https://wg21.link/LWG3871>`__","Adjust note about ``terminate``","2023-02 (Issaquah)","","",""
"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","2023-02 (Issaquah)","","",""
"`LWG3872 <https://wg21.link/LWG3872>`__","``basic_const_iterator`` should have custom ``iter_move``","2023-02 (Issaquah)","|Complete|","21",""
"`LWG3875 <https://wg21.link/LWG3875>`__","``std::ranges::repeat_view<T, IntegerClass>::iterator`` may be ill-formed","2023-02 (Issaquah)","|Complete|","17",""
"`LWG3876 <https://wg21.link/LWG3876>`__","Default constructor of ``std::layout_XX::mapping`` misses precondition","2023-02 (Issaquah)","","",""
"`LWG3877 <https://wg21.link/LWG3877>`__","Incorrect constraints on ``const``-qualified monadic overloads for ``std::expected``","2023-02 (Issaquah)","|Complete|","17",""
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx23Papers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"`P1899R3 <https://wg21.link/P1899R3>`__","``stride_view``","2022-07 (Virtual)","","",""
"`P2093R14 <https://wg21.link/P2093R14>`__","Formatted output","2022-07 (Virtual)","|Complete|","18",""
"`P2165R4 <https://wg21.link/P2165R4>`__","Compatibility between ``tuple``, ``pair`` and ``tuple-like`` objects","2022-07 (Virtual)","|Partial|","","Only the part for ``zip_view`` is implemented."
"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","2022-07 (Virtual)","","",""
"`P2278R4 <https://wg21.link/P2278R4>`__","``cbegin`` should always return a constant iterator","2022-07 (Virtual)","|Complete|","21",""
"`P2286R8 <https://wg21.link/P2286R8>`__","Formatting Ranges","2022-07 (Virtual)","|Complete|","16",""
"`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",""
"`P2302R4 <https://wg21.link/P2302R4>`__","``std::ranges::contains``","2022-07 (Virtual)","|Complete|","19",""
Expand Down
6 changes: 3 additions & 3 deletions libcxx/docs/Status/Cxx2cIssues.csv
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"`LWG3809 <https://wg21.link/LWG3809>`__","Is ``std::subtract_with_carry_engine<uint16_t>`` supposed to work","2023-11 (Kona)","","",""
"`LWG3892 <https://wg21.link/LWG3892>`__","Incorrect formatting of nested ranges and tuples","2023-11 (Kona)","|Complete|","17",""
"`LWG3897 <https://wg21.link/LWG3897>`__","``inout_ptr`` will not update raw pointer to 0","2023-11 (Kona)","|Complete|","19",""
"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","2023-11 (Kona)","","",""
"`LWG3946 <https://wg21.link/LWG3946>`__","The definition of ``const_iterator_t`` should be reworked","2023-11 (Kona)","|Complete|","21",""
"`LWG3947 <https://wg21.link/LWG3947>`__","Unexpected constraints on ``adjacent_transform_view::base()``","2023-11 (Kona)","","",""
"`LWG3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","2023-11 (Kona)","","",""
"`LWG3948 <https://wg21.link/LWG3948>`__","``possibly-const-range and as-const-pointer`` should be ``noexcept``","2023-11 (Kona)","|Complete|","21",""
"`LWG3949 <https://wg21.link/LWG3949>`__","``std::atomic<bool>``'s trivial destructor dropped in C++17 spec wording","2023-11 (Kona)","","",""
"`LWG3951 <https://wg21.link/LWG3951>`__","[expected.object.swap]: Using ``value()`` instead of ``has_value()``","2023-11 (Kona)","|Complete|","16",""
"`LWG3953 <https://wg21.link/LWG3953>`__","``iter_move`` for ``common_iterator`` and ``counted_iterator`` should return ``decltype(auto)``","2023-11 (Kona)","|Complete|","20",""
Expand Down Expand Up @@ -84,7 +84,7 @@
"`LWG3918 <https://wg21.link/LWG3918>`__","``std::uninitialized_move/_n`` and guaranteed copy elision","2024-11 (Wrocław)","","",""
"`LWG4014 <https://wg21.link/LWG4014>`__","LWG 3809 changes behavior of some existing ``std::subtract_with_carry_engine code``","2024-11 (Wrocław)","","",""
"`LWG4024 <https://wg21.link/LWG4024>`__","Underspecified destruction of objects created in ``std::make_shared_for_overwrite``/``std::allocate_shared_for_overwrite``","2024-11 (Wrocław)","","16",""
"`LWG4027 <https://wg21.link/LWG4027>`__","``possibly-const-range`` should prefer returning ``const R&``","2024-11 (Wrocław)","","",""
"`LWG4027 <https://wg21.link/LWG4027>`__","``possibly-const-range`` should prefer returning ``const R&``","2024-11 (Wrocław)","|Complete|","21",""
"`LWG4044 <https://wg21.link/LWG4044>`__","Confusing requirements for ``std::print`` on POSIX platforms","2024-11 (Wrocław)","","",""
"`LWG4064 <https://wg21.link/LWG4064>`__","Clarify that ``std::launder`` is not needed when using the result of ``std::memcpy``","2024-11 (Wrocław)","","",""
"`LWG4072 <https://wg21.link/LWG4072>`__","``std::optional`` comparisons: constrain harder","2024-11 (Wrocław)","","",""
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx2cPapers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"`P2819R2 <https://wg21.link/P2819R2>`__","Add tuple protocol to complex","2023-11 (Kona)","|Complete|","19",""
"`P2937R0 <https://wg21.link/P2937R0>`__","Freestanding: Remove ``strtok``","2023-11 (Kona)","","",""
"`P2833R2 <https://wg21.link/P2833R2>`__","Freestanding Library: inout expected span","2023-11 (Kona)","","",""
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","","",""
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","|Complete|","21","Implemented as a DR against C++23. (MSVC STL and libstdc++ do the same.)"
"`P2264R7 <https://wg21.link/P2264R7>`__","Make ``assert()`` macro user friendly for C and C++","2023-11 (Kona)","","",""
"`P1673R13 <https://wg21.link/P1673R13>`__","A free function linear algebra interface based on the BLAS","2023-11 (Kona)","","",""
"","","","","",""
Expand Down
4 changes: 3 additions & 1 deletion libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ set(files
__iterator/bounded_iter.h
__iterator/common_iterator.h
__iterator/concepts.h
__iterator/const_iterator.h
__iterator/counted_iterator.h
__iterator/cpp17_iterator_concepts.h
__iterator/data.h
Expand Down Expand Up @@ -679,14 +680,15 @@ set(files
__random/weibull_distribution.h
__ranges/access.h
__ranges/all.h
__ranges/as_const_view.h
__ranges/as_rvalue_view.h
__ranges/chunk_by_view.h
__ranges/common_view.h
__ranges/concepts.h
__ranges/const_access.h
__ranges/container_compatible_range.h
__ranges/counted.h
__ranges/dangling.h
__ranges/data.h
__ranges/drop_view.h
__ranges/drop_while_view.h
__ranges/elements_view.h
Expand Down
10 changes: 9 additions & 1 deletion libcxx/include/__algorithm/ranges_reverse_copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD

namespace ranges {

template <ranges::bidirectional_range _Range>
_LIBCPP_HIDE_FROM_ABI constexpr ranges::subrange<reverse_iterator<ranges::iterator_t<_Range>>,
reverse_iterator<ranges::iterator_t<_Range>>>
__reverse_range(_Range&& __range) {
auto __first = ranges::begin(__range);
return {std::make_reverse_iterator(ranges::next(__first, ranges::end(__range))), std::make_reverse_iterator(__first)};
}

template <class _InIter, class _OutIter>
using reverse_copy_result = in_out_result<_InIter, _OutIter>;

Expand All @@ -49,7 +57,7 @@ struct __reverse_copy {
requires indirectly_copyable<iterator_t<_Range>, _OutIter>
_LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result<borrowed_iterator_t<_Range>, _OutIter>
operator()(_Range&& __range, _OutIter __result) const {
auto __ret = ranges::copy(std::__reverse_range(__range), std::move(__result));
auto __ret = ranges::copy(ranges::__reverse_range(__range), std::move(__result));
return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)};
}
};
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__format/range_default_formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <__format/formatter.h>
#include <__format/range_formatter.h>
#include <__iterator/back_insert_iterator.h>
#include <__ranges/access.h>
#include <__ranges/concepts.h>
#include <__ranges/data.h>
#include <__ranges/from_range.h>
#include <__ranges/size.h>
#include <__type_traits/conditional.h>
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__format/range_formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include <__format/formatter_output.h>
#include <__format/parser_std_format_spec.h>
#include <__iterator/back_insert_iterator.h>
#include <__ranges/access.h>
#include <__ranges/concepts.h>
#include <__ranges/data.h>
#include <__ranges/from_range.h>
#include <__ranges/size.h>
#include <__type_traits/remove_cvref.h>
Expand Down
Loading