std::basic_...:starts_with(3)
π NAME π
okay so this is the std::basic_...:starts_with(3) page from the C++ Standard Libary manual, and the title is std::basic_string_view::starts_with β¨
The NAME block is literally std::basic_string_view::starts_with - std::basic_string_view::starts_with β yes bestie, it repeats itself and honestly? iconic π
π₯ SYNOPSIS π₯
constexpr bool starts_with( basic_string_view sv ) const noexcept;
(1) (since C++20)
constexpr bool starts_with( CharT ch ) const noexcept;
(2) (since C++20)
constexpr bool starts_with( const CharT* s ) const;
(3) (since C++20)
This function checks if the string view begins with the given prefix, where:
- the prefix is a string view. Effectively returns
basic_string_view(data(), std::min(size(), sv.size())) == sv. - the prefix is a single character. Effectively returns
!empty() && Traits::eq(front(), ch). - the prefix is a null-terminated character string. Effectively returns
starts_with(basic_string_view(s)).
π PARAMETERS π
svβ a string view which may be a result of implicit conversion fromstd::basic_stringchβ a single charactersβ a null-terminated character string
π RETURN VALUE π
true if the string view begins with the provided prefix, false otherwise. periodt β¨
π§ NOTES π§
Feature-test macro tea π«:
__cpp_lib_starts_ends_with- value:
201711L - Std:
(C++20) - Feature: String prefix and suffix checking:
starts_with()andends_with()
- value:
π EXAMPLE π
// Run this code
#include <cassert>
#include <string_view>
int main()
{
using namespace std::literals;
assert
(""
// (1) starts_with( basic_string_view )
&& "https://cppreference.com"sv.starts_with("http"sv) == true
&& "https://cppreference.com"sv.starts_with("ftp"sv) == false
// (2) starts_with( CharT )
&& "C++20"sv.starts_with('C') == true
&& "C++20"sv.starts_with('J') == false
// (3) starts_with( const CharT* )
&& std::string_view("string_view").starts_with("string") ==
true
&& std::string_view("string_view").starts_with("String") ==
false
);
}
π SEE ALSO π
ends_withβ checks if the string view ends with the given suffix(C++20)(public member function)starts_withβ checks if the string starts with the given prefix(C++20)(public member function ofstd::basic_string<CharT,Traits,Allocator>)ends_withβ checks if the string ends with the given suffix(C++20)(public member function ofstd::basic_string<CharT,Traits,Allocator>)containsβ checks if the string contains the given substring or character(C++23)(public member function ofstd::basic_string<CharT,Traits,Allocator>)containsβ checks if the string view contains the given substring or character(C++23)(public member function)compareβ compares two views (public member function)
okay bestie thatβs the whole page β source/version is http://cppreference.com, date 2024.06.10, and itβs the std::basic_...:starts_with(3) manual. slay and read your C++20 docs πβ¨
π¦ 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