std::basic_...w::contains(3)
hii bestie π welcome to std::basic_...w::contains(3) from the C++ Standard Libary manual. this page is literally the std::basic_string_view::contains glow-up, and it's giving "tiny utility that checks a substring" β¨
β¨ NAME β¨
std::basic_string_view::contains - std::basic_string_view::contains
π Synopsis π
okay so here's the synopsis, bestie β three overloads, all since C++23, and I kept every character:
constexpr bool contains( basic_string_view sv ) const noexcept; (1)
(since C++23)
constexpr bool contains( CharT c ) const noexcept; (2)
(since C++23)
constexpr bool contains( const CharT* s ) const; (3)
(since C++23)
Checks if the string view contains the given substring, where:
- the substring is a string view.
- the substring is a single character.
- the substring is a null-terminated character string.
All three overloads are equivalent to return find(x) != npos;, where x is the parameter. periodt π
π§Έ Parameters π§Έ
svβ a string viewcβ a single charactersβ a null-terminated character string
π Return value π
true if the string view contains the provided substring, false otherwise. no cap π«Ά
π Notes π
feature-test macro check, bestie π΅οΈββοΈ:
- Feature-test macro
__cpp_lib_string_containsβ Value202011Lβ Std(C++23)β Feature contains functions
π» Example π»
run this code, it's a static_assert baddie and it slays:
// Run this code
#include <string_view>
using namespace std::literals;
static_assert
(
// bool contains(basic_string_view x) const noexcept;
"https://cppreference.com"sv.contains("cpp"sv) == true and
"https://cppreference.com"sv.contains("php"sv) == false and
// bool contains(CharT x) const noexcept;
"C++23"sv.contains('+') == true and
"C++23"sv.contains('-') == false and
// bool contains(const CharT* x) const;
std::string_view("basic_string_view").contains("string") == true
and
std::string_view("basic_string_view").contains("String") == false
);
int main() {}
π See also π
starts_withβ checks if the string view starts with the given prefix (C++20) (public member function)ends_withβ checks if the string view ends with the given suffix (C++20) (public member function)findβ find characters in the view (public member function)substrβ returns a substring (public member function)containsβ checks if the string contains the given substring or character (C++23) (public member function ofstd::basic_string<CharT,Traits,Allocator>)
mwah π that's the whole page β source/version http://cppreference.com, date 2024.06.10, and it's the std::basic_...w::contains(3) page. now go check your substrings, bestie π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms