std::regex_traits::isctype

From cppreference.com
bool isctype( CharT c, char_class_type f ) const;

Determines whether the character c belongs to the character class identified by f, which, in turn, is a value returned by lookup_classname().

The version of this function provided in the standard library specializations of std::regex_traits, first converts f to some temporary value m of type std::ctype_base::mask in implementation-defined manner, then attempts to classify the character in the imbued locale by calling std::use_facet<std::ctype<CharT>>(getloc()).is(m, c). If that returned true, true is returned by isctype(). Otherwise, checks whether c equals '_' and the bitmask f corresponds to the character class [:w:], in which case true is returned. Otherwise, false is returned.

Note: the published standard is phrased incorrectly, requiring this function to return true for '_' in all cases. This is LWG issue 2018.

Contents

[edit] Parameters

c - the character to classify
f - the bitmask obtained from lookup_classname()

[edit] Return value

true if c is classified by f, false otherwise.

[edit] Example

#include <iostream>
#include <string>
#include <regex>
 
int main()
{
    std::regex_traits<char> t;
    std::string str_alnum = "alnum";
    auto a = t.lookup_classname(str_alnum.begin(), str_alnum.end());
    std::string str_w = "w"; // [:w:] is [:alnum:] plus '_'
    auto w = t.lookup_classname(str_w.begin(), str_w.end());
    std::cout << std::boolalpha
              << t.isctype('A', w) << ' ' << t.isctype('A', a) << '\n'
              << t.isctype('_', w) << ' ' << t.isctype('_', a) << '\n'
              << t.isctype(' ', w) << ' ' << t.isctype(' ', a) << '\n';
}

Output:

true true
true false
false false

[edit] See also

gets a character class by name
(public member function)
[virtual]
classifies a character or a character sequence
(virtual protected member function of std::ctype)