[libcxx-commits] [libcxx] [libc++][string] P3044R2: sub-`string_view` from `string` (PR #147095)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 20 01:58:50 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));
}
----------------
philnik777 wrote:
Well, I don't think the message is worth the complexity. "I want it anyways" doesn't sound like an argument why it's worth it.
https://github.com/llvm/llvm-project/pull/147095
More information about the libcxx-commits
mailing list