};
};
+ftms = {
+ name = string_subview;
+ values = {
+ v = 202506;
+ cxxmin = 26;
+ };
+};
+
ftms = {
name = to_underlying;
values = {
#endif /* !defined(__cpp_lib_string_resize_and_overwrite) */
#undef __glibcxx_want_string_resize_and_overwrite
+#if !defined(__cpp_lib_string_subview)
+# if (__cplusplus > 202302L)
+# define __glibcxx_string_subview 202506L
+# if defined(__glibcxx_want_all) || defined(__glibcxx_want_string_subview)
+# define __cpp_lib_string_subview 202506L
+# endif
+# endif
+#endif /* !defined(__cpp_lib_string_subview) */
+#undef __glibcxx_want_string_subview
+
#if !defined(__cpp_lib_to_underlying)
# if (__cplusplus >= 202100L)
# define __glibcxx_to_underlying 202102L
#define __glibcxx_want_constexpr_char_traits
#define __glibcxx_want_constexpr_string_view
#define __glibcxx_want_freestanding_string_view
-#define __glibcxx_want_string_view
#define __glibcxx_want_starts_ends_with
#define __glibcxx_want_string_contains
+#define __glibcxx_want_string_subview
+#define __glibcxx_want_string_view
#include <bits/version.h>
#if __cplusplus >= 201703L
return basic_string_view{_M_str + __pos, __rlen};
}
+#ifdef __glibcxx_string_subview // >= C++26
+ [[nodiscard]]
+ constexpr basic_string_view
+ subview(size_type __pos = 0, size_type __n = npos) const
+ { return substr(__pos, __n); }
+#endif
+
[[nodiscard]]
constexpr int
compare(basic_string_view __str) const noexcept
--- /dev/null
+// { dg-do run { target c++26 } }
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+#if __STDC_HOSTED__
+#include <stdexcept>
+#endif
+
+void test01() {
+ typedef std::string_view::size_type csize_type;
+ typedef std::string_view::const_reference cref;
+ typedef std::string_view::reference ref;
+ csize_type csz01;
+
+ const char str_lit01[] = "rockaway, pacifica";
+ const std::string_view 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");
+
+#if __STDC_HOSTED__
+ 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);
+ VERIFY(str02.begin() == str01.end());
+ VERIFY(true);
+ } catch (...) {
+ VERIFY(false);
+ }
+#endif // HOSTED
+}
+
+int main() {
+ test01();
+
+ return 0;
+}
--- /dev/null
+// { dg-do run { target c++26 } }
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+#if __STDC_HOSTED__
+#include <stdexcept>
+#endif
+
+void test01() {
+ typedef std::wstring_view::size_type csize_type;
+ typedef std::wstring_view::const_reference cref;
+ typedef std::wstring_view::reference ref;
+ csize_type csz01;
+
+ const wchar_t str_lit01[] = L"rockaway, pacifica";
+ const std::wstring_view 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");
+
+#if __STDC_HOSTED__
+ 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);
+ VERIFY(str02.begin() == str01.end());
+ VERIFY(true);
+ } catch (...) {
+ VERIFY(false);
+ }
+#endif // HOSTED
+}
+
+int main() {
+ test01();
+
+ return 0;
+}