std::char_traits (3) - Linux Manuals
std::char_traits: std::char_traits
NAME
std::char_traits - std::char_traits
Synopsis
Defined in header <string>
template<
class CharT
> class char_traits;
The char_traits class is a traits class template that abstracts basic character and string operations for a given character type. The defined operation set is such that generic algorithms almost always can be implemented in terms of it. It is thus possible to use such algorithms with almost any possible character or string type, just by supplying a customized char_traits class.
The char_traits class template serves as a basis for explicit instantiations. The user can provide_a_specialization for any custom character types. Several specializations are defined for the standard character types.
If an operation on traits emits an exception, the behavior is undefined.
The values of the member typedefs are as follows.
Specialization char_type int_type off_type pos_type state_type
char_traits<char> char int std::streamoff std::streampos std::mbstate_t
char_traits<wchar_t> wchar_t std::wint_t std::streamoff std::wstreampos std::mbstate_t
char_traits<char16_t> (C++11) char16_t std::uint_least16_t std::streamoff std::u16streampos std::mbstate_t
char_traits<char32_t> (C++11) char32_t std::uint_least32_t std::streamoff std::u32streampos std::mbstate_t
char_traits<char8_t> (C++20) char8_t unsigned int std::streamoff std::u8streampos std::mbstate_t
The semantics of the member functions are defined are as follows.
Specialization assign eq lt eof
char_traits<char> = == for unsigned char < for unsigned char EOF
char_traits<wchar_t> = == < WEOF
char_traits<char16_t> (C++11) = == < invalid UTF-16 code unit
char_traits<char32_t> (C++11) = == < invalid UTF-32 code unit
char_traits<char8_t> (C++20) = == < invalid UTF-8 code unit
The char_traits class template satisfies the requirements of CharTraits.
Member types
Type Definition
char_type CharT
int_type an integer type that can hold all values of char_type plus EOF
off_type implementation-defined
pos_type implementation-defined
state_type implementation-defined
Member functions
assign assigns a character
[static]
eq compares two characters
lt (public static member function)
[static]
move moves one character sequence onto another
[static]
copy copies a character sequence
[static]
compare lexicographically compares two character sequences
[static]
length returns the length of a character sequence
[static]
find finds a character in a character sequence
[static]
to_char_type converts int_type to equivalent char_type
[static]
to_int_type converts char_type to equivalent int_type
[static]
eq_int_type compares two int_type values
[static]
eof returns an eof value
[static]
not_eof checks whether a character is eof value
[static]
Example
User-defined character traits may be used to provide case-insensitive_comparison
// Run this code