Files
cppdraft_translate/cppdraft/char/traits/require.md
2025-10-25 03:02:53 +03:00

55 lines
6.3 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[char.traits.require]
# 27 Strings library [[strings]](./#strings)
## 27.2 Character traits [[char.traits]](char.traits#require)
### 27.2.2 Character traits requirements [char.traits.require]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L72)
In Table [87](#tab:char.traits.req "Table 87: Character traits requirements"),X denotes a traits class defining types and functions for the
character container typeC;c andd denote values of typeC;p andq denote values of typeconst C*;s denotes a value of typeC*;n,i andj denote values of typesize_t;e andf denote values of typeX::int_type;pos denotes a value of typeX::pos_type;
andr denotes an lvalue of typeC[.](#1.sentence-1)
No expression which is part of the character traits requirements
specified in [char.traits.require]
shall exit via an exception[.](#1.sentence-2)
Table [87](#tab:char.traits.req) — Character traits requirements [[tab:char.traits.req]](./tab:char.traits.req)
| [🔗](#tab:char.traits.req-row-1)<br>**Expression** | **Return type** | **Assertion/note** | **Complexity** |
| --- | --- | --- | --- |
| [🔗](#tab:char.traits.req-row-2) | | **pre-/post-condition** | |
| [🔗](#tab:char.traits.req-row-3)<br>X::char_type | C | | |
| [🔗](#tab:char.traits.req-row-4)<br>X::int_type | | (described in [[char.traits.typedefs]](char.traits.typedefs "27.2.3Traits typedefs")) | |
| [🔗](#tab:char.traits.req-row-5)<br>X::off_type | | (described in [[iostreams.limits.pos]](iostreams.limits.pos "31.2.3Positioning type limitations") and [[iostream.forward]](iostream.forward "31.3Forward declarations")) | |
| [🔗](#tab:char.traits.req-row-6)<br>X::pos_type | | (described in [[iostreams.limits.pos]](iostreams.limits.pos "31.2.3Positioning type limitations") and [[iostream.forward]](iostream.forward "31.3Forward declarations")) | |
| [🔗](#tab:char.traits.req-row-7)<br>X::state_type | | (described in [[char.traits.typedefs]](char.traits.typedefs "27.2.3Traits typedefs")) | |
| [🔗](#tab:char.traits.req-row-8)<br>X::eq(c,d) | bool | *Returns*: whether c is to be treated as equal to d[.](#tab:char.traits.req-row-8-column-3-sentence-1) | constant |
| [🔗](#tab:char.traits.req-row-9)<br>X::lt(c,d) | bool | *Returns*: whether c is to be treated as less than d[.](#tab:char.traits.req-row-9-column-3-sentence-1) | constant |
| [🔗](#tab:char.traits.req-row-10)<br>X::compare(p,q,n) | int | *Returns*: 0 if for each i in [0, n), X::eq(p[i],q[i]) is true; else, a negative value if, for some j in [0, n), X::lt(p[j],q[j]) is true and for each i in [0, j) X::eq(p[i],q[i]) is true; else a positive value[.](#tab:char.traits.req-row-10-column-3-sentence-1) | linear |
| [🔗](#tab:char.traits.req-row-11)<br>X::length(p) | size_t | *Returns*: the smallest i such that X::eq(p[i],charT()) is true[.](#tab:char.traits.req-row-11-column-3-sentence-1) | linear |
| [🔗](#tab:char.traits.req-row-12)<br>X::find(p,n,c) | const X::char_type* | *Returns*: the smallest q in [p, p+n) such that X::eq(*q,c) is true, nullptr otherwise[.](#tab:char.traits.req-row-12-column-3-sentence-1) | linear |
| [🔗](#tab:char.traits.req-row-13)<br>X::move(s,p,n) | X::char_type* | for each i in [0, n), performs X::assign(s[i],p[i])[.](#tab:char.traits.req-row-13-column-3-sentence-1)<br>Copies correctly even where the ranges [p, p+n) and [s, s+n) overlap[.](#tab:char.traits.req-row-13-column-3-sentence-2)<br> *Returns*: s[.](#tab:char.traits.req-row-13-column-3-sentence-3) | linear |
| [🔗](#tab:char.traits.req-row-14)<br>X::copy(s,p,n) | X::char_type* | *Preconditions*: The ranges [p, p+n) and [s, s+n) do not overlap[.](#tab:char.traits.req-row-14-column-3-sentence-1)<br>*Returns*: s[.](#tab:char.traits.req-row-14-column-3-sentence-2)<br> for each i in [0, n), performs X::assign(s[i],p[i])[.](#tab:char.traits.req-row-14-column-3-sentence-3) | linear |
| [🔗](#tab:char.traits.req-row-15)<br>X::assign(r,d) | (not used) | assigns r=d[.](#tab:char.traits.req-row-15-column-3-sentence-1) | constant |
| [🔗](#tab:char.traits.req-row-16)<br>X::assign(s,n,c) | X::char_type* | for each i in [0, n), performs X::assign(s[i],c)[.](#tab:char.traits.req-row-16-column-3-sentence-1)<br> *Returns*: s[.](#tab:char.traits.req-row-16-column-3-sentence-2) | linear |
| [🔗](#tab:char.traits.req-row-17)<br>X::not_eof(e) | int_type | *Returns*: e if X::eq_int_type(e,X::eof()) is false, otherwise a value f such that X::eq_int_type(f,X::eof()) is false[.](#tab:char.traits.req-row-17-column-3-sentence-1) | constant |
| [🔗](#tab:char.traits.req-row-18)<br>X::to_char_type(e) | X::char_type | *Returns*: if for some c, X::eq_int_type(e,X::to_int_type(c)) is true, c; else some unspecified value[.](#tab:char.traits.req-row-18-column-3-sentence-1) | constant |
| [🔗](#tab:char.traits.req-row-19)<br>X::to_int_type(c) | X::int_type | *Returns*: some value e, constrained by the definitions of to_char_type and eq_int_type[.](#tab:char.traits.req-row-19-column-3-sentence-1) | constant |
| [🔗](#tab:char.traits.req-row-20)<br>X::eq_int_type(e,f) | bool | *Returns*: for all c and d, X::eq(c,d) is equal to X::eq_int_type(X::to_int_type(c), X::to_int_type(d)); otherwise, yields true if e and f are both copies of X::eof(); otherwise, yields false if one of e and f is a copy of X::eof() and the other is not; otherwise the value is unspecified[.](#tab:char.traits.req-row-20-column-3-sentence-1) | constant |
| [🔗](#tab:char.traits.req-row-21)<br>X::eof() | 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[.](#tab:char.traits.req-row-21-column-3-sentence-1) | constant |
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L197)
The class template
[🔗](#lib:char_traits)
template<class charT> struct char_traits; is provided in the header [<string>](string.syn#header:%3cstring%3e "27.4.2Header <string> synopsis[string.syn]") as a basis for explicit specializations[.](#2.sentence-1)