std::ctype::scan_not(3)
π NAME π
std::ctype::scan_not β bestie, it's literally std::ctype::scan_not. That's the whole name, no notes. π
This one lives in the C++ Standard Library and it's from the <locale> girlies β¨
β¨ Synopsis β¨
Okay so first things first, this is defined in header <locale>, k? Don't come for me if you forget the include. π«Ά
const char* scan_not( mask m, const char* beg, const char* end ) const;
πΈ What it actually does πΈ
It locates the first character in the character array [beg, end) that does not satisfy the classification mask m. That is, the very first character c such that
table()[(unsigned char)c] & m
would return false. Iconic behavior honestly. π
Lowkey important caveat bestie: if(unsigned char)c >= std::ctype<char>::table_size, then an implementation-defined value gets substituted instead oftable()[(unsigned char)c]β and it's possibly different for different values ofc. So like... don't vibe too hard on that edge case, mwah. π
π¦ Parameters π¦
mβ the mask to search for πbegβ pointer to the first character in an array of characters to search πendβ the one-past-the-end pointer for the array of characters to search π
β Return value β
A pointer to the first character in [beg, end) that does not satisfy the mask β or end if no such character was found. So if everybody in the group chat passes the vibe check, you just get end back. Periodt. π§
π Notes π
Unlike the primary template std::ctype, this specialization doesn't perform a virtual function call when classifying characters. No virtual dispatch, no drama, we love to see it. β¨
To customize the behavior, a derived class may provide a non-default classification table to the base class constructor. That's your main character move right there. π₯
π Example π
// Run this code
#include <iostream>
#include <iterator>
#include <locale>
int main()
{
auto& f = std::use_facet<std::ctype<char>>(std::locale());
// skip leading whitespace
char s1[] = " \t\t\n Test";
const char* p1 = f.scan_not(std::ctype_base::space, std::begin(s1), std::end(s1));
std::cout << '\'' << p1 << "'\n";
// skip leading digits
char s2[] = "123456789abcd";
const char* p2 = f.scan_not(std::ctype_base::digit, std::begin(s2), std::end(s2));
std::cout << '\'' << p2 << "'\n";
}
Output:
'Test'
'abcd'
See? We skipped the whitespace, we skipped the digits, and what's left is giving clean string. Ate. π π
π See also π
do_scan_notβ locates the first character in a sequence that fails given classification β [virtual] (virtual protected member function ofstd::ctype<CharT>) πΈscan_isβ locates the first character in a sequence that conforms to given classification, using the classification table (public member function) π¦
Okay that's the whole page bestie, ily, go read your locale facets responsibly π«Ά
Source: http://cppreference.com Β· Version: 2024.06.10 Β· Page: std::ctype::scan_not(3) β drink water, unplug your charger at 80%, and ngl this doc was kinda iconic. ππ
π¦ 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