class template
<locale>

std::ctype

template <class charT> class ctype;
Character type facet

The ctype standard facet classifies and transforms characters, adapting the functionality of the C library header <cctype> to C++ locales.

The ctype class template has a protected destructor: Programs shall only construct objects of derived classes, or use those installed in locale objects (through use_facet).

All standard locale objects support at least the following facet instantiations of the ctype class template as part of the ctype category:
facets in locale objectsdescription
ctype<char>narrow characters
produces the same results as the functions in header <cctype> for the classic locale * specialized with a particular implementation (see specializations below)
ctype<wchar_t>wide characters

Template parameters

charT
Character type.
Aliased as member char_type.

Member types

member typedefinitiondescription
char_typeThe template parameter (charT)Character type
The class also inherits ctype_base::mask, which is used extensively as a parameter and return type by member functions (see ctype_base).

Member constants

The following member constants are inherited from ctype_base; They are used to identify character categories.
member constanttypevaluedescription
spacectype_base::maskunspecified (unique bits)white-space character
printctype_base::maskunspecified (unique bits)printable character
cntrlctype_base::maskunspecified (unique bits)control character
upperctype_base::maskunspecified (unique bits)uppercase letter
lowerctype_base::maskunspecified (unique bits)lowercase letter
alphactype_base::maskunspecified (unique bits)alphabetic character
digitctype_base::maskunspecified (unique bits)decimal digit
punctctype_base::maskunspecified (unique bits)punctuation character
xdigitctype_base::maskunspecified (unique bits)hexadecimal digit
alnumctype_base::maskalpha|digitalpha-numeric character
graphctype_base::maskalnum|punctcharacter with graphic representation
member constanttypevaluedescription
spacectype_base::maskunspecified (unique bits)white-space character
printctype_base::maskunspecified (unique bits)printable character
cntrlctype_base::maskunspecified (unique bits)control character
upperctype_base::maskunspecified (unique bits)uppercase letter
lowerctype_base::maskunspecified (unique bits)lowercase letter
alphactype_base::maskunspecified (unique bits)alphabetic character
digitctype_base::maskunspecified (unique bits)decimal digit
punctctype_base::maskunspecified (unique bits)punctuation character
xdigitctype_base::maskunspecified (unique bits)hexadecimal digit
blankctype_base::maskunspecified (unique bits)blank character
alnumctype_base::maskalpha|digitalpha-numeric character
graphctype_base::maskalnum|punctcharacter with graphic representation
See <cctype> for details on how ASCII characters are classified with respect to these categories.

The class also contains a public static constant of type locale::id, that uniquely identifies facets with ctype semantics.

Public member functions


Character classification


Character transformation


Virtual protected member functions

The class defines the virtual protected members which implement the behavior by default of their respective public member functions:

Along with the class destructor:

Specializations

At least the following specializations of this template are provided in all library implementations:
specialization
ctype<char>
ctype<wchar_t>

Particular specialization: ctype<char>

On the char specialization, some of the member functions are implemented inline instead of calling their do_ counterparts (this is the case for members is, scan_is and scan_not).

It has a different constructor, and keeps an internal table of elements of type ctype::mask with the classification of each of the characters in the character set: The value of each element in the array corresponds to the classification of the character given by its order position.

The size of this table is indicated by an additional static public member constant:
member constanttypevaluedescription
table_sizeconst size_timplementation-specific (at least 256)The size of the table
This specialization contains two additional protected members:
This specialization contains two additional public members:

Note that do_is, do_scan_is and do_scan_not are not members of the char specialization.