This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

369
cppdraft/locale/num/get.md Normal file
View File

@@ -0,0 +1,369 @@
[locale.num.get]
# 28 Text processing library [[text]](./#text)
## 28.3 Localization library [[localization]](localization#locale.num.get)
### 28.3.4 Standard locale categories [[locale.categories]](locale.categories#locale.num.get)
#### 28.3.4.3 The numeric category [[category.numeric]](category.numeric#locale.num.get)
#### 28.3.4.3.2 Class template num_get [locale.num.get]
#### [28.3.4.3.2.1](#general) General [[locale.num.get.general]](locale.num.get.general)
[🔗](#lib:num_get)
namespace std {template<class charT, class InputIterator = istreambuf_iterator<charT>>class num_get : public locale::facet {public:using char_type = charT; using iter_type = InputIterator; explicit num_get(size_t refs = 0);
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, bool& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, long long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned short& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned int& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned long long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, float& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, double& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, long double& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, void*& v) const; static locale::id id; protected:~num_get(); virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, bool& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned short& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned int& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned long long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, float& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, double& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long double& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, void*& v) const; };}
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2490)
The facet num_get is used to parse numeric values
from an input sequence such as an istream[.](#general-1.sentence-1)
#### [28.3.4.3.2.2](#facet.num.get.members) Members [[facet.num.get.members]](facet.num.get.members)
[🔗](#lib:num_get,get)
`iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, bool& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, long& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, long long& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned short& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned int& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned long& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned long long& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, float& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, double& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, long double& val) const;
iter_type get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, void*& val) const;
`
[1](#facet.num.get.members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2523)
*Returns*: do_get(in, end, str, err, val)[.](#facet.num.get.members-1.sentence-1)
#### [28.3.4.3.2.3](#facet.num.get.virtuals) Virtual functions [[facet.num.get.virtuals]](facet.num.get.virtuals)
[🔗](#lib:num_get,do_get)
`iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, long& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, long long& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned short& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned int& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned long& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, unsigned long long& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, float& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, double& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, long double& val) const;
iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, void*& val) const;
`
[1](#facet.num.get.virtuals-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2555)
*Effects*: Reads characters from in,
interpreting them according tostr.flags(),use_facet<ctype<charT>>(loc), anduse_facet<numpunct<charT>>(loc),
where loc is str.getloc()[.](#facet.num.get.virtuals-1.sentence-1)
[2](#facet.num.get.virtuals-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2564)
The details of this operation occur in three stages:
- [(2.1)](#facet.num.get.virtuals-2.1)
Stage 1:
Determine a conversion specifier[.](#facet.num.get.virtuals-2.1.sentence-1)
- [(2.2)](#facet.num.get.virtuals-2.2)
Stage 2:
Extract characters from in and
determine a corresponding char value for
the format expected by the conversion specification determined in stage 1[.](#facet.num.get.virtuals-2.2.sentence-1)
- [(2.3)](#facet.num.get.virtuals-2.3)
Stage 3:
Store results[.](#facet.num.get.virtuals-2.3.sentence-1)
[3](#facet.num.get.virtuals-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2581)
The details of the stages are presented below[.](#facet.num.get.virtuals-3.sentence-1)
- [Stage 1:](#facet.num.get.virtuals-3.1)
The function initializes local variables viafmtflags flags = str.flags();
fmtflags basefield = (flags & ios_base::basefield);
fmtflags uppercase = (flags & ios_base::uppercase);
fmtflags boolalpha = (flags & ios_base::boolalpha);
For conversion to an integral type,
the function determines the integral conversion specifier
as indicated in Table [95](#tab:facet.num.get.int "Table 95: Integer conversions")[.](#facet.num.get.virtuals-3.1.sentence-2)
The table is ordered[.](#facet.num.get.virtuals-3.1.sentence-3)
That is, the first line whose condition is true applies[.](#facet.num.get.virtuals-3.1.sentence-4)
Table [95](#tab:facet.num.get.int) — Integer conversions [[tab:facet.num.get.int]](./tab:facet.num.get.int)
| [🔗](#tab:facet.num.get.int-row-1)<br> **State** | **stdio equivalent** |
| --- | --- |
| [🔗](#tab:facet.num.get.int-row-2)<br> basefield == oct | %o |
| [🔗](#tab:facet.num.get.int-row-3)<br> basefield == hex | %X |
| [🔗](#tab:facet.num.get.int-row-4)<br> basefield == 0 | %i |
| [🔗](#tab:facet.num.get.int-row-5)<br> signed integral type | %d |
| [🔗](#tab:facet.num.get.int-row-6)<br> unsigned integral type | %u |
For conversions to a floating-point type the specifier is %g[.](#facet.num.get.virtuals-3.1.sentence-5)
For conversions to void* the specifier is %p[.](#facet.num.get.virtuals-3.1.sentence-6)
A length modifier is added to the conversion specification, if needed,
as indicated in Table [96](#tab:facet.num.get.length "Table 96: Length modifier")[.](#facet.num.get.virtuals-3.1.sentence-7)
Table [96](#tab:facet.num.get.length) — Length modifier [[tab:facet.num.get.length]](./tab:facet.num.get.length)
| [🔗](#tab:facet.num.get.length-row-1)<br> **Type** | **Length modifier** |
| --- | --- |
| [🔗](#tab:facet.num.get.length-row-2)<br> short | h |
| [🔗](#tab:facet.num.get.length-row-3)<br> unsigned short | h |
| [🔗](#tab:facet.num.get.length-row-4)<br> long | l |
| [🔗](#tab:facet.num.get.length-row-5)<br> unsigned long | l |
| [🔗](#tab:facet.num.get.length-row-6)<br> long long | ll |
| [🔗](#tab:facet.num.get.length-row-7)<br> unsigned long long | ll |
| [🔗](#tab:facet.num.get.length-row-8)<br> double | l |
| [🔗](#tab:facet.num.get.length-row-9)<br> long double | L |
- [Stage 2:](#facet.num.get.virtuals-3.2)
If in == end then stage 2 terminates[.](#facet.num.get.virtuals-3.2.sentence-1)
Otherwise a charT is taken from in and
local variables are initialized as if bychar_type ct = *in;char c = src[find(atoms, atoms + sizeof(src) - 1, ct) - atoms];if (ct == use_facet<numpunct<charT>>(loc).decimal_point()) c = '.';bool discard = ct == use_facet<numpunct<charT>>(loc).thousands_sep()&& use_facet<numpunct<charT>>(loc).grouping().length() != 0; where the values src and atoms are defined as if by:static const char src[] = "0123456789abcdefpxABCDEFPX+-";
char_type atoms[sizeof(src)];
use_facet<ctype<charT>>(loc).widen(src, src + sizeof(src), atoms); for this value of loc[.](#facet.num.get.virtuals-3.2.sentence-2)
If discard is true,
then if '.' has not yet been accumulated,
then the position of the character is remembered,
but the character is otherwise ignored[.](#facet.num.get.virtuals-3.2.sentence-3)
Otherwise, if '.' has already been accumulated,
the character is discarded and Stage 2 terminates[.](#facet.num.get.virtuals-3.2.sentence-4)
If it is not discarded,
then a check is made to determine
if c is allowed as the next character of
an input field of the conversion specifier returned by Stage 1[.](#facet.num.get.virtuals-3.2.sentence-5)
If so, it is accumulated[.](#facet.num.get.virtuals-3.2.sentence-6)
If the character is either discarded or accumulated
then in is advanced by ++in and processing returns to the beginning of stage 2[.](#facet.num.get.virtuals-3.2.sentence-7)
[*Example [1](#facet.num.get.virtuals-example-1)*:
Given an input sequence of "0x1a.bp+07p",
* [(3.2.1)](#facet.num.get.virtuals-3.2.1)
if the conversion specifier returned by Stage 1 is %d,"0" is accumulated;
* [(3.2.2)](#facet.num.get.virtuals-3.2.2)
if the conversion specifier returned by Stage 1 is %i,"0x1a" are accumulated;
* [(3.2.3)](#facet.num.get.virtuals-3.2.3)
if the conversion specifier returned by Stage 1 is %g,"0x1a.bp+07" are accumulated[.](#facet.num.get.virtuals-3.2.sentence-8)
In all cases, the remainder is left in the input[.](#facet.num.get.virtuals-3.2.sentence-9)
— *end example*]
- [Stage 3:](#facet.num.get.virtuals-3.3)
The sequence of chars accumulated in stage 2 (the field)
is converted to a numeric value by the rules of one of the functions
declared in the header [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2Header <cstdlib> synopsis[cstdlib.syn]"):
* [(3.3.1)](#facet.num.get.virtuals-3.3.1)
For a signed integer value, the function strtoll[.](#facet.num.get.virtuals-3.3.1.sentence-1)
* [(3.3.2)](#facet.num.get.virtuals-3.3.2)
For an unsigned integer value, the function strtoull[.](#facet.num.get.virtuals-3.3.2.sentence-1)
* [(3.3.3)](#facet.num.get.virtuals-3.3.3)
For a float value, the function strtof[.](#facet.num.get.virtuals-3.3.3.sentence-1)
* [(3.3.4)](#facet.num.get.virtuals-3.3.4)
For a double value, the function strtod[.](#facet.num.get.virtuals-3.3.4.sentence-1)
* [(3.3.5)](#facet.num.get.virtuals-3.3.5)
For a long double value, the function strtold[.](#facet.num.get.virtuals-3.3.5.sentence-1)
The numeric value to be stored can be one of:
* [(3.3.6)](#facet.num.get.virtuals-3.3.6)
zero, if the conversion function does not convert the entire field[.](#facet.num.get.virtuals-3.3.6.sentence-1)
* [(3.3.7)](#facet.num.get.virtuals-3.3.7)
the most positive (or negative) representable value,
if the field to be converted to a signed integer type represents a value
too large positive (or negative) to be represented in val[.](#facet.num.get.virtuals-3.3.7.sentence-1)
* [(3.3.8)](#facet.num.get.virtuals-3.3.8)
the most positive representable value,
if the field to be converted to an unsigned integer type represents a value
that cannot be represented in val[.](#facet.num.get.virtuals-3.3.8.sentence-1)
* [(3.3.9)](#facet.num.get.virtuals-3.3.9)
the converted value, otherwise[.](#facet.num.get.virtuals-3.3.9.sentence-1)
The resultant numeric value is stored in val[.](#facet.num.get.virtuals-3.3.sentence-3)
If the conversion function does not convert the entire field, or
if the field represents a value outside the range of representable values,ios_base::failbit is assigned to err[.](#facet.num.get.virtuals-3.3.sentence-4)
[4](#facet.num.get.virtuals-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2726)
Digit grouping is checked[.](#facet.num.get.virtuals-4.sentence-1)
That is, the positions of discarded
separators are examined for consistency withuse_facet<numpunct<charT>>(loc).grouping()[.](#facet.num.get.virtuals-4.sentence-2)
If they are not consistent
then ios_base::failbit is assigned to err[.](#facet.num.get.virtuals-4.sentence-3)
[5](#facet.num.get.virtuals-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2734)
In any case,
if stage 2 processing was terminated by the test for in == end then err |= ios_base::eofbit is performed[.](#facet.num.get.virtuals-5.sentence-1)
[🔗](#lib:do_get,num_get_)
`iter_type do_get(iter_type in, iter_type end, ios_base& str,
ios_base::iostate& err, bool& val) const;
`
[6](#facet.num.get.virtuals-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2747)
*Effects*: If (str.flags() & ios_base::boolalpha) == 0 then input proceeds as it would for a long except that if a value is being stored into val,
the value is determined according to the following:
If the value to be stored is 0 then false is stored[.](#facet.num.get.virtuals-6.sentence-1)
If the value is 1 then true is stored[.](#facet.num.get.virtuals-6.sentence-2)
Otherwise true is stored andios_base::failbit is assigned to err[.](#facet.num.get.virtuals-6.sentence-3)
[7](#facet.num.get.virtuals-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2758)
Otherwise target sequences are determined “as if” by
calling the members falsename() and truename() of
the facet obtained by use_facet<numpunct<charT>>(str.getloc())[.](#facet.num.get.virtuals-7.sentence-1)
Successive characters in the range [in, end) (see [[sequence.reqmts]](sequence.reqmts "23.2.4Sequence containers"))
are obtained and matched against
corresponding positions in the target sequences
only as necessary to identify a unique match[.](#facet.num.get.virtuals-7.sentence-2)
The input iterator in is compared to end only when necessary to obtain a character[.](#facet.num.get.virtuals-7.sentence-3)
If a target sequence is uniquely matched,val is set to the corresponding value[.](#facet.num.get.virtuals-7.sentence-4)
Otherwise false is stored andios_base::failbit is assigned to err[.](#facet.num.get.virtuals-7.sentence-5)
[8](#facet.num.get.virtuals-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2773)
The in iterator is always left pointing one position beyond
the last character successfully matched[.](#facet.num.get.virtuals-8.sentence-1)
If val is set, then err is set to str.goodbit;
or to str.eofbit if,
when seeking another character to match,
it is found that (in == end)[.](#facet.num.get.virtuals-8.sentence-2)
If val is not set, then err is set to str.failbit;
or to (str.failbit | str.eofbit) if the reason for the failure was that (in == end)[.](#facet.num.get.virtuals-8.sentence-3)
[*Example [2](#facet.num.get.virtuals-example-2)*:
For targets true: "a" and false: "abb",
the input sequence "a" yieldsval == true and err == str.eofbit;
the input sequence "abc" yieldserr = str.failbit, with in ending at the 'c' element[.](#facet.num.get.virtuals-8.sentence-4)
For targets true: "1" and false: "0",
the input sequence "1" yieldsval == true and err == str.goodbit[.](#facet.num.get.virtuals-8.sentence-5)
For empty targets (""),
any input sequence yields err == str.failbit[.](#facet.num.get.virtuals-8.sentence-6)
— *end example*]
[9](#facet.num.get.virtuals-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2796)
*Returns*: in[.](#facet.num.get.virtuals-9.sentence-1)

View File

@@ -0,0 +1,58 @@
[locale.num.get.general]
# 28 Text processing library [[text]](./#text)
## 28.3 Localization library [[localization]](localization#locale.num.get.general)
### 28.3.4 Standard locale categories [[locale.categories]](locale.categories#locale.num.get.general)
#### 28.3.4.3 The numeric category [[category.numeric]](category.numeric#locale.num.get.general)
#### 28.3.4.3.2 Class template num_get [[locale.num.get]](locale.num.get#general)
#### 28.3.4.3.2.1 General [locale.num.get.general]
[🔗](#lib:num_get)
namespace std {template<class charT, class InputIterator = istreambuf_iterator<charT>>class num_get : public locale::facet {public:using char_type = charT; using iter_type = InputIterator; explicit num_get(size_t refs = 0);
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, bool& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, long long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned short& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned int& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, unsigned long long& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, float& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, double& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, long double& v) const;
iter_type get(iter_type in, iter_type end, ios_base&,
ios_base::iostate& err, void*& v) const; static locale::id id; protected:~num_get(); virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, bool& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned short& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned int& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, unsigned long long& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, float& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, double& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, long double& v) const; virtual iter_type do_get(iter_type, iter_type, ios_base&,
ios_base::iostate& err, void*& v) const; };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L2490)
The facet num_get is used to parse numeric values
from an input sequence such as an istream[.](#1.sentence-1)