std::basic_...last_not_of(3)
π std::basic_string_view::find_last_not_of β the manual, but make it make sense
okay bestie, welcome to the std::basic_string_view::find_last_not_of page π this is the C++ Standard Library manual, and today we're reading the std::basic_string_view::find_last_not_of entry together. yes the title is the same thing twice, that's just how these pages are, don't @ me π«Ά
β¨ SYNOPSIS β¨
four overloads, all since C++17 πΈ watch the const and noexcept placement, she's specific:
(1) constexpr size_type
find_last_not_of( basic_string_view v, size_type pos = npos ) const noexcept;
(2) constexpr size_type
find_last_not_of( CharT ch, size_type pos = npos ) const noexcept;
(3) constexpr size_type
find_last_not_of( const CharT* s, size_type pos, size_type count ) const;
(4) constexpr size_type
find_last_not_of( const CharT* s, size_type pos = npos ) const;
the whole vibe: finds the last character not equal to any of the characters in the given character sequence. and lowkey the search only ever considers the interval [0, pos] β nothing outside it, periodt π
- (1) finds the last character in this view that's not equal to any of the characters of
v, starting at positionpos. - (2) equivalent to
find_last_not_of(basic_string_view(std::addressof(ch), 1), pos). - (3) equivalent to
find_last_not_of(basic_string_view(s, count), pos). - (4) equivalent to
find_last_not_of(basic_string_view(s), pos).
π PARAMETERS π
vβ the view to search for πposβ position at which to start the search πcountβ length of the string of characters to compare πsβ pointer to a string of characters to comparechβ character to compare
π RETURN VALUE π
the position of the last character not equal to any of the characters in the given string β iconic, she found it β¨ or npos if no such character is found π (that's the "nope, nothing, sorry bestie" answer).
π¦ COMPLEXITY π¦
O(size() * v.size()) at worst. yes, that's the worst case, ngl it can get expensive, plan accordingly π
π EXAMPLE π
// Run this code
#include <string_view>
using std::operator""sv;
int main()
{
static_assert(1 == "BCDEF"sv.find_last_not_of("DEF"));
// ^
static_assert(2 == "BCDEFG"sv.find_last_not_of("EFG", 3));
// ^
static_assert(2 == "ABBA"sv.find_last_not_of('A'));
// ^
static_assert(1 == "ABBA"sv.find_last_not_of('A', 1));
// ^
}
the little ^ comments are doing the most and honestly? they ate π they're pointing at exactly which character lands where. static_assert means this whole thing is checked at compile time, so if you break it, the compiler will let you know loudly π
π SEE ALSO π
findβ find characters in the view (public member function)rfindβ find the last occurrence of a substring (public member function)find_first_ofβ find first occurrence of characters (public member function)find_last_ofβ find last occurrence of characters (public member function)find_first_not_ofβ find first absence of characters (public member function)find_last_not_ofβ find last absence of characters (public member function ofstd::basic_string<CharT,Traits,Allocator>)
β οΈ heads up: that last one is a differentfind_last_not_ofβ it belongs tostd::basic_string<CharT,Traits,Allocator>, not the string_view. same name, different family member, don't mix them up bestie π«Ά
okay that's the whole page!! π source is cppreference.com, dated 2024.06.10, and this was the std::basic_...last_not_of(3) page from the C++ Standard Library manual. go write some static_asserts, you're gonna slay πΈβ¨π
π¦ 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