< cpp‎ | regex‎ | regex traits
Revision as of 12:38, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td class="t-dcl-nopad">
bool isctype( CharT c, char_class_type f ) const;

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Determines whether the character c belongs to the character class identified by f, which, in turn, is a value returned by Template:rlpf.

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.



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

Return value

true if c is classified by f, false otherwise.


#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';


true true
true false
false false

See also

Template:cpp/locale/ctype/dcl list do is
gets a character class by name
(public member function)