{ return __sv_type(this->data(), this->size()).ends_with(__x); }
#endif // C++20
+#if __cplusplus > 202002L
+ bool
+ contains(basic_string_view<_CharT, _Traits> __x) const noexcept
+ { return __sv_type(this->data(), this->size()).contains(__x); }
+
+ bool
+ contains(_CharT __x) const noexcept
+ { return __sv_type(this->data(), this->size()).contains(__x); }
+
+ bool
+ contains(const _CharT* __x) const noexcept
+ { return __sv_type(this->data(), this->size()).contains(__x); }
+#endif // C++23
+
// Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
template<typename, typename, typename> friend class basic_stringbuf;
};
{ return __sv_type(this->data(), this->size()).ends_with(__x); }
#endif // C++20
+#if __cplusplus >= 202011L \
+ || (__cplusplus == 202002L && !defined __STRICT_ANSI__)
+ bool
+ contains(basic_string_view<_CharT, _Traits> __x) const noexcept
+ { return __sv_type(this->data(), this->size()).contains(__x); }
+
+ bool
+ contains(_CharT __x) const noexcept
+ { return __sv_type(this->data(), this->size()).contains(__x); }
+
+ bool
+ contains(const _CharT* __x) const noexcept
+ { return __sv_type(this->data(), this->size()).contains(__x); }
+#endif // C++23
+
# ifdef _GLIBCXX_TM_TS_INTERNAL
friend void
::_txnal_cow_string_C1_for_exceptions(void* that, const char* s,
{ return this->ends_with(basic_string_view(__x)); }
#endif // C++20
+#if __cplusplus > 202002L
+#define __cpp_lib_string_contains 202011L
+ constexpr bool
+ contains(basic_string_view __x) const noexcept
+ { return this->find(__x) != npos; }
+
+ constexpr bool
+ contains(_CharT __x) const noexcept
+ { return this->find(__x) != npos; }
+
+ constexpr bool
+ contains(const _CharT* __x) const noexcept
+ { return this->find(__x) != npos; }
+#endif // C++23
+
// [string.view.find], searching
constexpr size_type
#endif
#if __cplusplus > 201703L
-// c++2a
+// c++20
#define __cpp_lib_atomic_flag_test 201907L
#define __cpp_lib_atomic_float 201711L
#define __cpp_lib_atomic_ref 201806L
#define __cpp_lib_to_address 201711L
#define __cpp_lib_to_array 201907L
#endif
-#endif // C++2a
+
+#if __cplusplus > 202002L
+// c++2b
+#define __cpp_lib_string_contains 202011L
+#endif // C++2b
+#endif // C++20
#endif // C++17
#endif // C++14
#endif // C++11
--- /dev/null
+// { dg-options "-std=gnu++23" }
+// { dg-do run { target c++23 } }
+
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string contains
+
+#include <string>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ const std::string haystack("no place for needles");
+
+ VERIFY(haystack.contains(std::string("")));
+ VERIFY(haystack.contains(std::string("no")));
+ VERIFY(haystack.contains(std::string("needles")));
+ VERIFY(haystack.contains(std::string(" for ")));
+ VERIFY(!haystack.contains(std::string("places")));
+
+ VERIFY(haystack.contains(std::string_view("")));
+ VERIFY(haystack.contains(std::string_view("no")));
+ VERIFY(haystack.contains(std::string_view("needles")));
+ VERIFY(haystack.contains(std::string_view(" for ")));
+ VERIFY(!haystack.contains(std::string_view("places")));
+
+ VERIFY(!haystack.contains('\0'));
+ VERIFY(haystack.contains('n'));
+ VERIFY(haystack.contains('e'));
+ VERIFY(haystack.contains('s'));
+ VERIFY(!haystack.contains('x'));
+
+ VERIFY(haystack.contains(""));
+ VERIFY(haystack.contains("no"));
+ VERIFY(haystack.contains("needles"));
+ VERIFY(haystack.contains(" for "));
+ VERIFY(!haystack.contains("places"));
+
+ const std::string nothing;
+ VERIFY(nothing.contains(""));
+ VERIFY(!nothing.contains('\0'));
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++23" }
+// { dg-do run { target c++23 } }
+
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string contains
+
+#include <string>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ const std::wstring haystack(L"no place for needles");
+
+ VERIFY(haystack.contains(std::wstring(L"")));
+ VERIFY(haystack.contains(std::wstring(L"no")));
+ VERIFY(haystack.contains(std::wstring(L"needles")));
+ VERIFY(haystack.contains(std::wstring(L" for ")));
+ VERIFY(!haystack.contains(std::wstring(L"places")));
+
+ VERIFY(haystack.contains(std::wstring_view(L"")));
+ VERIFY(haystack.contains(std::wstring_view(L"no")));
+ VERIFY(haystack.contains(std::wstring_view(L"needles")));
+ VERIFY(haystack.contains(std::wstring_view(L" for ")));
+ VERIFY(!haystack.contains(std::wstring_view(L"places")));
+
+ VERIFY(!haystack.contains('\0'));
+ VERIFY(haystack.contains('n'));
+ VERIFY(haystack.contains('e'));
+ VERIFY(haystack.contains('s'));
+ VERIFY(!haystack.contains('x'));
+
+ VERIFY(haystack.contains(L""));
+ VERIFY(haystack.contains(L"no"));
+ VERIFY(haystack.contains(L"needles"));
+ VERIFY(haystack.contains(L" for "));
+ VERIFY(!haystack.contains(L"places"));
+
+ const std::wstring nothing;
+ VERIFY(nothing.contains(L""));
+ VERIFY(!nothing.contains('\0'));
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
int
main()
-{
+{
test01();
return 0;
}
int
main()
-{
+{
test01();
return 0;
}
--- /dev/null
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view contains
+
+#include <string_view>
+
+#ifndef __cpp_lib_string_contains
+# error "Feature-test macro for contains missing in <string_view>"
+#elif __cpp_lib_string_contains != 202011L
+# error "Feature-test macro for contains has wrong value in <string_view>"
+#endif
+
+void
+test01()
+{
+ constexpr std::string_view haystack("no place for needles");
+
+ static_assert(haystack.contains(std::string_view("")));
+ static_assert(haystack.contains(std::string_view("no")));
+ static_assert(haystack.contains(std::string_view("needles")));
+ static_assert(haystack.contains(std::string_view(" for ")));
+ static_assert(!haystack.contains(std::string_view("places")));
+
+ static_assert(!haystack.contains('\0'));
+ static_assert(haystack.contains('n'));
+ static_assert(haystack.contains('e'));
+ static_assert(haystack.contains('s'));
+ static_assert(!haystack.contains('x'));
+
+ static_assert(haystack.contains(""));
+ static_assert(haystack.contains("no"));
+ static_assert(haystack.contains("needles"));
+ static_assert(haystack.contains(" for "));
+ static_assert(!haystack.contains("places"));
+
+ constexpr std::string_view nothing;
+ static_assert(nothing.contains(""));
+ static_assert(!nothing.contains('\0'));
+}
--- /dev/null
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <version>
+
+#ifndef __cpp_lib_string_contains
+# error "Feature-test macro for contains missing in <string_view>"
+#elif __cpp_lib_string_contains != 202011L
+# error "Feature-test macro for contains has wrong value in <string_view>"
+#endif
--- /dev/null
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view contains
+
+#include <string_view>
+
+void
+test01()
+{
+ constexpr std::wstring_view haystack = L"no place for needles";
+
+ static_assert(haystack.contains(std::wstring_view(L"")));
+ static_assert(haystack.contains(std::wstring_view(L"no")));
+ static_assert(haystack.contains(std::wstring_view(L"needles")));
+ static_assert(haystack.contains(std::wstring_view(L" for ")));
+ static_assert(!haystack.contains(std::wstring_view(L"places")));
+
+ static_assert(!haystack.contains('\0'));
+ static_assert(haystack.contains('n'));
+ static_assert(haystack.contains('e'));
+ static_assert(haystack.contains('s'));
+ static_assert(!haystack.contains('x'));
+
+ static_assert(haystack.contains(L""));
+ static_assert(haystack.contains(L"no"));
+ static_assert(haystack.contains(L"needles"));
+ static_assert(haystack.contains(L" for "));
+ static_assert(!haystack.contains(L"places"));
+
+ constexpr std::wstring_view nothing;
+ static_assert(nothing.contains(L""));
+ static_assert(!nothing.contains('\0'));
+}