CharTraits is a traits class that abstracts basic character and string operations for a given character type. Most standard library string and input/output classes require a CharTraits template type parameter alongside a corresponding character template type parameter.
[edit] RequirementsNo operation listed below on CharTraits may throw an exception.
Given
CharT
, a character typeX
, a CharTraits type for type CharT
CharT
CharT*
X::int_type
X::pos_type
X::state_type
CharT
X::char_type
CharT
X::int_type
A type that can hold all valid values of X::char_type
plus X::eof() X::off_type
Invokes implementation-defined behavior if not std::streamoff when X
is used as the traits template parameter in input/output classes. X::pos_type
X
is used as the traits template parameter in input/output classesX::state_type
Destructible, CopyAssignable, CopyConstructible, DefaultConstructible [edit] Expressions Expression Return type Semantics Complexity X::eq(c, d) bool Returns: whether c is to be treated as equal to d Constant X::lt(c, d) bool Returns: whether c is to be treated as less than d Constant X::compare(p, q, n) int Returns:
[
â0â,
n)
, X::eq(p[i], q[i]) is true[
â0â,
n)
, X::lt(p[j], q[j]) is true and[
â0â,
j)
, X::eq(p[i], q[i]) is true[
p,
p + n)
such that X::eq(*q, c) is trueX::char_type*
[
â0â,
n)
, performs X::assign(s[i], p[i])[
p,
p + n)
and [
s,
s + n)
overlapX::char_type*
[
p,
p + n)
and [
s,
s + n)
do not overlap[
â0â,
n)
, performs X::assign(s[i], p[i])X::char_type*
[
â0â,
n)
, performs X::assign(s[i], c).X::int_type
Returns:
X::char_type
Returns:
X::int_type
Returns: some value e, constrained by the definitions of X::to_char_type
and X::eq_int_type
Constant X::eq_int_type(e, f) bool
X::int_type
Returns: a value e such that X::eq_int_type(e, X::to_int_type(c)) is false for all values c Constant [edit] Standard library
CharTraits is required by the following standard library class templates as a template type parameter:
CharTraits is satisfied by the following standard library explicit specializations of std::char_traits:
template<> class char_traits<wchar_t>;
template<> class char_traits<char8_t>;
template<> class char_traits<char16_t>;
(since C++20)
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 335 C++98 the requirements on the binary overload ofassign
did not prevent assignments to rvalues its first argument
X::state_type
was only
[
s,
s + n)
, which is too weak[1] requires [
p,
p + n)
and
[
s,
s + n)
not to overlap
[
p,
p + n)
and [
s,
s + n)
can overlap, using std::memcpy to implement X::copy
results in undefined behavior in this case.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4