Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_variant`` ``202106L``
---------------------------------------------------------- -----------------
``__cpp_lib_view_interface`` ``202606L``
---------------------------------------------------------- -----------------
**C++23**
----------------------------------------------------------------------------
``__cpp_lib_adaptor_iterator_pair_constructor`` ``202106L``
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx29Papers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"`P2414R12 <https://wg21.link/P2414R12>`__","Pointer lifetime-end zap proposed solutions","2026-06 (Brno)","","","`#204392 <https://github.com/llvm/llvm-project/issues/204392>`__","Voted as a Defect Report."
"`P3319R6 <https://wg21.link/P3319R6>`__","Add an ``iota`` object for ``simd`` (and more)","2026-06 (Brno)","","","`#204393 <https://github.com/llvm/llvm-project/issues/204393>`__",""
"`P3798R1 <https://wg21.link/P3798R1>`__","The unexpected in ``std::expected``","2026-06 (Brno)","","","`#204394 <https://github.com/llvm/llvm-project/issues/204394>`__",""
"`P3052R2 <https://wg21.link/P3052R2>`__","``view_interface::at()``","2026-06 (Brno)","","","`#204395 <https://github.com/llvm/llvm-project/issues/204395>`__",""
"`P3052R2 <https://wg21.link/P3052R2>`__","``view_interface::at()``","2026-06 (Brno)","|Complete|,"23","`#204395 <https://github.com/llvm/llvm-project/issues/204395>`__",""
"`P4206R0 <https://wg21.link/P4206R0>`__","Revert string support in ``std::constant_wrapper``","2026-06 (Brno)","","","`#203336 <https://github.com/llvm/llvm-project/issues/203336>`__","To be applied as a Defect Report."
"`P3395R6 <https://wg21.link/P3395R6>`__","Fix encoding issues and add a formatter for ``std::error_code``","2026-06 (Brno)","","","`#204396 <https://github.com/llvm/llvm-project/issues/204396>`__",""
"`P3505R4 <https://wg21.link/P3505R4>`__","Fix the default floating-point representation in ``std::format``","2026-06 (Brno)","","","`#204397 <https://github.com/llvm/llvm-project/issues/204397>`__","To be applied as a Defect Report."
Expand Down
22 changes: 22 additions & 0 deletions libcxx/include/__ranges/view_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <__concepts/same_as.h>
#include <__config>
#include <__iterator/concepts.h>
#include <__iterator/distance.h>
#include <__iterator/iterator_traits.h>
#include <__iterator/prev.h>
#include <__memory/pointer_traits.h>
Expand All @@ -25,6 +26,7 @@
#include <__type_traits/is_class.h>
#include <__type_traits/make_unsigned.h>
#include <__type_traits/remove_cv.h>
#include <stdexcept>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down Expand Up @@ -159,6 +161,26 @@ class view_interface {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](range_difference_t<_RARange> __index) const {
return ranges::begin(__derived())[__index];
}

template <random_access_range _RARange = _Derived>
requires sized_range<_RARange> // freestanding-deleted
[[nodiscard]] constexpr decltype(auto) at(range_difference_t<_RARange> __index) {
if (__index < 0 || __index >= ranges::distance(__derived())) {
std::__throw_out_of_range(
"Precondition `0 <= __index < distance()` not satisfied. `.at(__index)` called with out-of-bounds index.");
}
return (*this)[__index];
}

template <random_access_range _RARange = const _Derived>
requires sized_range<_RARange> // freestanding-deleted
[[nodiscard]] constexpr decltype(auto) at(range_difference_t<_RARange> __index) const {
if (__index < 0 || __index >= ranges::distance(__derived())) {
std::__throw_out_of_range(
"Precondition `0 <= __index < distance()` not satisfied. `.at(__index)` called with out-of-bounds index.");
}
return (*this)[__index];
}
};

} // namespace ranges
Expand Down
2 changes: 2 additions & 0 deletions libcxx/include/version
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ __cpp_lib_unwrap_ref 201811L <functional>
__cpp_lib_variant 202306L <variant>
202106L // C++20
202102L // C++17
__cpp_lib_view_interface 202606L <ranges>
__cpp_lib_void_t 201411L <type_traits>

*/
Expand Down Expand Up @@ -487,6 +488,7 @@ __cpp_lib_void_t 201411L <type_traits>
# define __cpp_lib_unwrap_ref 201811L
# undef __cpp_lib_variant
# define __cpp_lib_variant 202106L
# define __cpp_lib_view_interface 202606L
#endif

#if _LIBCPP_STD_VER >= 23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ void test() {
v[Diff{0}];
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::as_const(v)[Diff{0}];

// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
v.at(Diff{0});
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::as_const(v).at(Diff{0});
}
1 change: 1 addition & 0 deletions libcxx/test/libcxx/transitive_includes/cxx23.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ algorithm iosfwd
algorithm limits
algorithm optional
algorithm ratio
algorithm stdexcept
algorithm tuple
algorithm version
any cstdint
Expand Down
1 change: 1 addition & 0 deletions libcxx/test/libcxx/transitive_includes/cxx26.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ algorithm iosfwd
algorithm limits
algorithm optional
algorithm ratio
algorithm stdexcept
algorithm tuple
algorithm version
any cstdint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
# error "__cpp_lib_ranges_zip should not be defined before c++23"
# endif

# ifdef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should not be defined before c++20"
# endif

#elif TEST_STD_VER == 14

# ifdef __cpp_lib_default_template_type_for_algorithm_values
Expand Down Expand Up @@ -142,6 +146,10 @@
# error "__cpp_lib_ranges_zip should not be defined before c++23"
# endif

# ifdef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should not be defined before c++20"
# endif

#elif TEST_STD_VER == 17

# ifdef __cpp_lib_default_template_type_for_algorithm_values
Expand Down Expand Up @@ -204,6 +212,10 @@
# error "__cpp_lib_ranges_zip should not be defined before c++23"
# endif

# ifdef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should not be defined before c++20"
# endif

#elif TEST_STD_VER == 20

# ifdef __cpp_lib_default_template_type_for_algorithm_values
Expand Down Expand Up @@ -269,6 +281,13 @@
# error "__cpp_lib_ranges_zip should not be defined before c++23"
# endif

# ifndef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should be defined in c++20"
# endif
# if __cpp_lib_view_interface != 202606L
# error "__cpp_lib_view_interface should have the value 202606L in c++20"
# endif

#elif TEST_STD_VER == 23

# ifdef __cpp_lib_default_template_type_for_algorithm_values
Expand Down Expand Up @@ -385,6 +404,13 @@
# error "__cpp_lib_ranges_zip should have the value 202110L in c++23"
# endif

# ifndef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should be defined in c++23"
# endif
# if __cpp_lib_view_interface != 202606L
# error "__cpp_lib_view_interface should have the value 202606L in c++23"
# endif

#elif TEST_STD_VER > 23

# if !defined(_LIBCPP_VERSION)
Expand Down Expand Up @@ -516,6 +542,13 @@
# error "__cpp_lib_ranges_zip should have the value 202110L in c++26"
# endif

# ifndef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should be defined in c++26"
# endif
# if __cpp_lib_view_interface != 202606L
# error "__cpp_lib_view_interface should have the value 202606L in c++26"
# endif

#endif // TEST_STD_VER > 23

// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,10 @@
# error "__cpp_lib_variant should not be defined before c++17"
# endif

# ifdef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should not be defined before c++20"
# endif

# ifdef __cpp_lib_void_t
# error "__cpp_lib_void_t should not be defined before c++17"
# endif
Expand Down Expand Up @@ -1946,6 +1950,10 @@
# error "__cpp_lib_variant should not be defined before c++17"
# endif

# ifdef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should not be defined before c++20"
# endif

# ifdef __cpp_lib_void_t
# error "__cpp_lib_void_t should not be defined before c++17"
# endif
Expand Down Expand Up @@ -3137,6 +3145,10 @@
# error "__cpp_lib_variant should have the value 202102L in c++17"
# endif

# ifdef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should not be defined before c++20"
# endif

# ifndef __cpp_lib_void_t
# error "__cpp_lib_void_t should be defined in c++17"
# endif
Expand Down Expand Up @@ -4595,6 +4607,13 @@
# error "__cpp_lib_variant should have the value 202106L in c++20"
# endif

# ifndef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should be defined in c++20"
# endif
# if __cpp_lib_view_interface != 202606L
# error "__cpp_lib_view_interface should have the value 202606L in c++20"
# endif

# ifndef __cpp_lib_void_t
# error "__cpp_lib_void_t should be defined in c++20"
# endif
Expand Down Expand Up @@ -6281,6 +6300,13 @@
# error "__cpp_lib_variant should have the value 202106L in c++23"
# endif

# ifndef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should be defined in c++23"
# endif
# if __cpp_lib_view_interface != 202606L
# error "__cpp_lib_view_interface should have the value 202606L in c++23"
# endif

# ifndef __cpp_lib_void_t
# error "__cpp_lib_void_t should be defined in c++23"
# endif
Expand Down Expand Up @@ -8303,6 +8329,13 @@
# error "__cpp_lib_variant should have the value 202306L in c++26"
# endif

# ifndef __cpp_lib_view_interface
# error "__cpp_lib_view_interface should be defined in c++26"
# endif
# if __cpp_lib_view_interface != 202606L
# error "__cpp_lib_view_interface should have the value 202606L in c++26"
# endif

# ifndef __cpp_lib_void_t
# error "__cpp_lib_void_t should be defined in c++26"
# endif
Expand Down
Loading
Loading