[libcxx-commits] [libcxx] [libc++][string] P3044R2: sub-`string_view` from `string` (PR #147095)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 20 01:47:42 PDT 2025


================
@@ -457,14 +459,25 @@ public:
     return __rlen;
   }
 
-  _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view substr(size_type __pos = 0, size_type __n = npos) const {
+  _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI inline basic_string_view
+  __subview(size_type __pos, size_type __n, const char* __msg) const {
     // Use the `__assume_valid` form of the constructor to avoid an unnecessary check. Any substring of a view is a
     // valid view. In particular, `size()` is known to be smaller than `numeric_limits<difference_type>::max()`, so the
     // new size is also smaller. See also https://github.com/llvm/llvm-project/issues/91634.
-    return __pos > size() ? (__throw_out_of_range("string_view::substr"), basic_string_view())
+    return __pos > size() ? (__throw_out_of_range(__msg), basic_string_view())
                           : basic_string_view(__assume_valid(), data() + __pos, std::min(__n, size() - __pos));
   }
----------------
H-G-Hristov wrote:

That's fair. I still want to output the message with the correct method name, so code duplication is unavoidable.

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


More information about the libcxx-commits mailing list