{ return basic_string(*this,
_M_check(__pos, "basic_string::substr"), __n); }
+#ifdef __glibcxx_string_subview // >= C++26
+ /**
+ * @brief Get a subview.
+ * @param __pos Index of first character (default 0).
+ * @param __n Number of characters in subview (default remainder).
+ * @return The subview.
+ * @throw std::out_of_range If __pos > size().
+ *
+ * Construct and return a subview using the `__n` characters starting at
+ * `__pos`. If the string is too short, use the remainder of the
+ * characters. If `__pos` is beyond the end of the string, out_of_range
+ * is thrown.
+ */
+ [[nodiscard]]
+ constexpr basic_string_view<_CharT, _Traits>
+ subview(size_type __pos = 0, size_type __n = npos) const
+ { return __sv_type(*this).subview(__pos, __n); }
+#endif
+
/**
* @brief Compare to a string.
* @param __str String to compare against.
{ return basic_string(*this,
_M_check(__pos, "basic_string::substr"), __n); }
+#ifdef __glibcxx_string_subview // >= C++26
+ /**
+ * @brief Get a subview.
+ * @param __pos Index of first character (default 0).
+ * @param __n Number of characters in subview (default remainder).
+ * @return The subview.
+ * @throw std::out_of_range If __pos > size().
+ *
+ * Construct and return a subview using the `__n` characters starting at
+ * `__pos`. If the string is too short, use the remainder of the
+ * characters. If `__pos` is beyond the end of the string, out_of_range
+ * is thrown.
+ */
+ [[nodiscard]]
+ constexpr basic_string_view<_CharT, _Traits>
+ subview(size_type __pos = 0, size_type __n = npos) const
+ { return __sv_type(*this).subview(__pos, __n); }
+#endif
+
/**
* @brief Compare to a string.
* @param __str String to compare against.
#define __glibcxx_want_erase_if
#define __glibcxx_want_nonmember_container_access
#define __glibcxx_want_string_resize_and_overwrite
+#define __glibcxx_want_string_subview
#define __glibcxx_want_string_udls
#define __glibcxx_want_to_string
#include <bits/version.h>
--- /dev/null
+// { dg-do run { target c++26 } }
+
+#include <stdexcept>
+#include <string>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void test01(void) {
+ typedef std::string::size_type csize_type;
+ typedef std::string::const_reference cref;
+ typedef std::string::reference ref;
+ csize_type csz01;
+
+ const char str_lit01[] = "rockaway, pacifica";
+ const std::string str01(str_lit01);
+ std::string_view str02;
+
+ csz01 = str01.size();
+ str02 = str01.subview(0, 1);
+ VERIFY(str02 == "r");
+ str02 = str01.subview(10);
+ VERIFY(str02 == "pacifica");
+
+ try {
+ str02 = str01.subview(csz01 + 1);
+ VERIFY(false);
+ } catch (std::out_of_range &fail) {
+ VERIFY(true);
+ } catch (...) {
+ VERIFY(false);
+ }
+
+ try {
+ str02 = str01.subview(csz01);
+ VERIFY(str02.size() == 0);
+ } catch (std::out_of_range &fail) {
+ VERIFY(false);
+ } catch (...) {
+ VERIFY(false);
+ }
+}
+
+int main() {
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-do run { target c++26 } }
+
+#include <stdexcept>
+#include <string>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void test01(void) {
+ typedef std::wstring::size_type csize_type;
+ typedef std::wstring::const_reference cref;
+ typedef std::wstring::reference ref;
+ csize_type csz01;
+
+ const wchar_t str_lit01[] = L"rockaway, pacifica";
+ const std::wstring str01(str_lit01);
+ std::wstring_view str02;
+
+ csz01 = str01.size();
+ str02 = str01.subview(0, 1);
+ VERIFY(str02 == L"r");
+ str02 = str01.subview(10);
+ VERIFY(str02 == L"pacifica");
+
+ try {
+ str02 = str01.subview(csz01 + 1);
+ VERIFY(false);
+ } catch (std::out_of_range &fail) {
+ VERIFY(true);
+ } catch (...) {
+ VERIFY(false);
+ }
+
+ try {
+ str02 = str01.subview(csz01);
+ VERIFY(str02.size() == 0);
+ } catch (std::out_of_range &fail) {
+ VERIFY(false);
+ } catch (...) {
+ VERIFY(false);
+ }
+}
+
+int main() {
+ test01();
+ return 0;
+}