[libcxx-commits] [libcxx] [libc++][ranges] P3052R2: `view_interface::at()` (PR #205012)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 28 07:09:41 PDT 2026


================
@@ -159,6 +161,30 @@ class view_interface {
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](range_difference_t<_RARange> __index) const {
     return ranges::begin(__derived())[__index];
   }
+
+#  if _LIBCPP_STD_VER >= 29
+
+  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.");
----------------
Zingam wrote:

I slightly shorten the proposed message. Please verify if you are OK with it.

https://github.com/llvm/llvm-project/pull/205012


More information about the libcxx-commits mailing list