|
4391 | 4391 | They may use other public members of
|
4392 | 4392 | \tcode{istream}.
|
4393 | 4393 |
|
4394 |
| -\pnum |
4395 |
| -If |
4396 |
| -\tcode{rdbuf()->sbumpc()} |
4397 |
| -or |
4398 |
| -\tcode{rdbuf()->sgetc()} |
4399 |
| -returns |
4400 |
| -\tcode{traits::eof()}, |
4401 |
| -then the input function, except as explicitly noted otherwise, completes its actions and does |
4402 |
| -\tcode{setstate(eofbit)}, |
4403 |
| -which may throw |
4404 |
| -\tcode{ios_base::failure}\iref{iostate.flags}, before returning. |
4405 |
| - |
4406 |
| -\pnum |
4407 |
| -If one of these called functions throws an exception, then unless explicitly noted otherwise, |
4408 |
| -the input function sets |
4409 |
| -\tcode{badbit} |
4410 |
| -in the error state. |
4411 |
| -If |
4412 |
| -\tcode{badbit} |
4413 |
| -is set in |
4414 |
| -\tcode{exceptions()}, |
4415 |
| -the input function |
4416 |
| -rethrows the exception without completing its actions, otherwise |
4417 |
| -it does not throw anything and proceeds as if the called function had returned |
4418 |
| -a failure indication. |
4419 |
| - |
4420 | 4394 | \rSec4[istream.cons]{Constructors}
|
4421 | 4395 |
|
4422 | 4396 | \indexlibraryctor{basic_istream}%
|
|
4647 | 4621 | \rSec4[istream.formatted.reqmts]{Common requirements}
|
4648 | 4622 |
|
4649 | 4623 | \pnum
|
4650 |
| -Each formatted input function begins execution by constructing an object of class |
| 4624 | +Each formatted input function begins execution by constructing |
| 4625 | +an object of type \tcode{ios_base::iostate}, termed the local error state, and |
| 4626 | +initializing it to \tcode{ios_base::goodbit}. |
| 4627 | +It then creates an object of class |
4651 | 4628 | \tcode{sentry}
|
4652 | 4629 | with the
|
4653 | 4630 | \tcode{noskipws}
|
|
4661 | 4638 | \tcode{bool},
|
4662 | 4639 | the function endeavors
|
4663 | 4640 | to obtain the requested input.
|
| 4641 | +Otherwise, |
| 4642 | +if the \tcode{sentry} constructor exits by throwing an exception or |
| 4643 | +if the \tcode{sentry} object produces \tcode{false} |
| 4644 | +when converted to a value of type \tcode{bool}, |
| 4645 | +the function returns without attempting to obtain any input. |
| 4646 | +If \tcode{rdbuf()->sbumpc()} or \tcode{rdbuf()->sgetc()} |
| 4647 | +returns \tcode{traits::eof()}, then |
| 4648 | +\tcode{ios_base::eofbit} is set in the local error state and |
| 4649 | +the input function stops trying to obtain the requested input. |
4664 | 4650 | If an exception is thrown during input then
|
4665 |
| -\tcode{ios_base::badbit} |
4666 |
| -is turned on |
4667 |
| -\begin{footnote} |
4668 |
| -This is done without causing an |
4669 |
| -\tcode{ios_base::failure} |
4670 |
| -to be thrown. |
4671 |
| -\end{footnote} |
4672 |
| -in |
4673 |
| -\tcode{*this}'s |
4674 |
| -error state. |
4675 |
| -If |
4676 |
| -\tcode{(exceptions()\&badbit) != 0} |
4677 |
| -then the exception is rethrown. |
| 4651 | +\tcode{ios_base::badbit} is set in the local error state, |
| 4652 | +\tcode{*this}'s error state is set to the local error state, and |
| 4653 | +the exception is rethrown if \tcode{(exceptions() \& badbit) != 0}. |
| 4654 | +After extraction is done, the input function calls \tcode{setstate}, which |
| 4655 | +sets \tcode{*this}'s error state to the local error state, and |
| 4656 | +may throw an exception. |
4678 | 4657 | In any case, the formatted input function destroys the
|
4679 | 4658 | \tcode{sentry}
|
4680 | 4659 | object.
|
|
4705 | 4684 | \tcode{num_get<>}\iref{locale.num.get} object to perform parsing the input
|
4706 | 4685 | stream data.
|
4707 | 4686 | These extractors behave as formatted input functions (as described in~\ref{istream.formatted.reqmts}). After a \tcode{sentry} object is constructed, the
|
4708 |
| -conversion occurs as if performed by the following code fragment: |
| 4687 | +conversion occurs as if performed by the following code fragment, |
| 4688 | +where \tcode{state} represents the input function's local error state: |
4709 | 4689 | \begin{codeblock}
|
4710 | 4690 | using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
|
4711 |
| -iostate err = iostate::goodbit; |
4712 |
| -use_facet<numget>(loc).get(*this, 0, *this, err, val); |
4713 |
| -setstate(err); |
| 4691 | +use_facet<numget>(loc).get(*this, 0, *this, state, val); |
4714 | 4692 | \end{codeblock}
|
4715 | 4693 | In the above fragment,
|
4716 | 4694 | \tcode{loc}
|
|
4743 | 4721 | (using the same notation as for the preceding code fragment):
|
4744 | 4722 | \begin{codeblock}
|
4745 | 4723 | using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
|
4746 |
| -iostate err = ios_base::goodbit; |
4747 | 4724 | long lval;
|
4748 |
| -use_facet<numget>(loc).get(*this, 0, *this, err, lval); |
| 4725 | +use_facet<numget>(loc).get(*this, 0, *this, state, lval); |
4749 | 4726 | if (lval < numeric_limits<short>::min()) {
|
4750 |
| - err |= ios_base::failbit; |
| 4727 | + state |= ios_base::failbit; |
4751 | 4728 | val = numeric_limits<short>::min();
|
4752 | 4729 | } else if (numeric_limits<short>::max() < lval) {
|
4753 |
| - err |= ios_base::failbit; |
| 4730 | + state |= ios_base::failbit; |
4754 | 4731 | val = numeric_limits<short>::max();
|
4755 | 4732 | } else
|
4756 | 4733 | val = static_cast<short>(lval);
|
4757 |
| -setstate(err); |
4758 | 4734 | \end{codeblock}
|
4759 | 4735 | \end{itemdescr}
|
4760 | 4736 |
|
|
4769 | 4745 | (using the same notation as for the preceding code fragment):
|
4770 | 4746 | \begin{codeblock}
|
4771 | 4747 | using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
|
4772 |
| -iostate err = ios_base::goodbit; |
4773 | 4748 | long lval;
|
4774 |
| -use_facet<numget>(loc).get(*this, 0, *this, err, lval); |
| 4749 | +use_facet<numget>(loc).get(*this, 0, *this, state, lval); |
4775 | 4750 | if (lval < numeric_limits<int>::min()) {
|
4776 |
| - err |= ios_base::failbit; |
| 4751 | + state |= ios_base::failbit; |
4777 | 4752 | val = numeric_limits<int>::min();
|
4778 | 4753 | } else if (numeric_limits<int>::max() < lval) {
|
4779 |
| - err |= ios_base::failbit; |
| 4754 | + state |= ios_base::failbit; |
4780 | 4755 | val = numeric_limits<int>::max();
|
4781 | 4756 | } else
|
4782 | 4757 | val = static_cast<int>(lval);
|
4783 |
| -setstate(err); |
4784 | 4758 | \end{codeblock}
|
4785 | 4759 | \end{itemdescr}
|
4786 | 4760 |
|
|
4818 | 4792 | (using the same notation as for the preceding code fragment):
|
4819 | 4793 | \begin{codeblock}
|
4820 | 4794 | using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
|
4821 |
| -iostate err = ios_base::goodbit; |
4822 | 4795 | FP fval;
|
4823 |
| -use_facet<numget>(loc).get(*this, 0, *this, err, fval); |
| 4796 | +use_facet<numget>(loc).get(*this, 0, *this, state, fval); |
4824 | 4797 | if (fval < -numeric_limits<@\placeholder{extended-floating-point-type}@>::max()) {
|
4825 |
| - err |= ios_base::failbit; |
| 4798 | + state |= ios_base::failbit; |
4826 | 4799 | val = -numeric_limits<@\placeholder{extended-floating-point-type}@>::max();
|
4827 | 4800 | } else if (numeric_limits<@\placeholder{extended-floating-point-type}@>::max() < fval) {
|
4828 |
| - err |= ios_base::failbit; |
| 4801 | + state |= ios_base::failbit; |
4829 | 4802 | val = numeric_limits<@\placeholder{extended-floating-point-type}@>::max();
|
4830 | 4803 | } else {
|
4831 | 4804 | val = static_cast<@\placeholder{extended-floating-point-type}@>(fval);
|
4832 | 4805 | }
|
4833 |
| -setstate(err); |
4834 | 4806 | \end{codeblock}
|
4835 | 4807 | \begin{note}
|
4836 | 4808 | When the extended floating-point type has
|
|
4954 | 4926 | \tcode{width(0)}.
|
4955 | 4927 |
|
4956 | 4928 | \pnum
|
4957 |
| -If the function extracted no characters, it calls |
4958 |
| -\tcode{setstate(failbit)}, |
4959 |
| -which may throw |
4960 |
| -\tcode{ios_base::\brk{}failure}\iref{iostate.flags}. |
| 4929 | +If the function extracted no characters, |
| 4930 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 4931 | +before \tcode{setstate} is called. |
4961 | 4932 |
|
4962 | 4933 | \pnum
|
4963 | 4934 | \returns
|
|
4979 | 4950 | \effects
|
4980 | 4951 | Behaves like a formatted input member (as described in~\ref{istream.formatted.reqmts})
|
4981 | 4952 | of \tcode{in}.
|
4982 |
| -After a |
4983 |
| -\tcode{sentry} |
4984 |
| -object is constructed |
4985 |
| -a character is extracted from \tcode{in}, if one is available, and stored in \tcode{c}. |
4986 |
| -Otherwise, the function calls |
4987 |
| -\tcode{in.setstate(fail\-bit)}. |
| 4953 | +A character is extracted from \tcode{in}, if one is available, and stored in \tcode{c}. |
| 4954 | +Otherwise, |
| 4955 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 4956 | +before \tcode{setstate} is called. |
4988 | 4957 |
|
4989 | 4958 | \pnum
|
4990 | 4959 | \returns
|
|
5020 | 4989 | \end{itemize}
|
5021 | 4990 |
|
5022 | 4991 | \pnum
|
5023 |
| -If the function inserts no characters, it calls |
5024 |
| -\tcode{setstate(failbit)}, |
5025 |
| -which may throw |
5026 |
| -\tcode{ios_base::\brk{}failure}\iref{iostate.flags}. |
5027 |
| -If it inserted no characters because it caught |
5028 |
| -an exception thrown while extracting characters from |
5029 |
| -\tcode{*this} |
5030 |
| -and |
5031 |
| -\tcode{failbit} |
5032 |
| -is set in |
5033 |
| -\tcode{exceptions()}\iref{iostate.flags}, |
5034 |
| -then the caught exception is rethrown. |
| 4992 | +If the function inserts no characters, |
| 4993 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 4994 | +before \tcode{setstate} is called. |
5035 | 4995 |
|
5036 | 4996 | \pnum
|
5037 | 4997 | \returns
|
|
5041 | 5001 | \rSec3[istream.unformatted]{Unformatted input functions}
|
5042 | 5002 |
|
5043 | 5003 | \pnum
|
5044 |
| -Each unformatted input function begins execution by constructing an object of class |
| 5004 | +Each unformatted input function begins execution by constructing |
| 5005 | +an object of type \tcode{ios_base::iostate}, termed the local error state, and |
| 5006 | +initializing it to \tcode{ios_base::goodbit}. |
| 5007 | +It then creates an object of class |
5045 | 5008 | \tcode{sentry}
|
5046 | 5009 | with the default argument
|
5047 | 5010 | \tcode{noskipws}
|
|
5056 | 5019 | the function endeavors
|
5057 | 5020 | to obtain the requested input.
|
5058 | 5021 | Otherwise, if the \tcode{sentry} constructor exits by throwing an exception or if
|
5059 |
| -the \tcode{sentry} object returns \tcode{false}, when converted to a value of type |
| 5022 | +the \tcode{sentry} object produces \tcode{false}, when converted to a value of type |
5060 | 5023 | \tcode{bool},
|
5061 | 5024 | the function returns without attempting to obtain any input.
|
5062 | 5025 | In either case the number of extracted characters is set to 0;
|
5063 | 5026 | unformatted input functions taking a character array of nonzero size as
|
5064 | 5027 | an argument shall also store a null character (using
|
5065 | 5028 | \tcode{charT()})
|
5066 | 5029 | in the first location of the array.
|
| 5030 | +If \tcode{rdbuf()->sbumpc()} or \tcode{rdbuf()->sgetc()} |
| 5031 | +returns \tcode{traits::eof()}, then |
| 5032 | +\tcode{ios_base::eofbit} is set in the local error state and |
| 5033 | +the input function stops trying to obtain the requested input. |
5067 | 5034 | If an exception is thrown during input then
|
5068 |
| -\tcode{ios_base::badbit} |
5069 |
| -is turned on |
5070 |
| -\begin{footnote} |
5071 |
| -This is done without causing an |
5072 |
| -\tcode{ios_base::failure} |
5073 |
| -to be thrown. |
5074 |
| -\end{footnote} |
5075 |
| -in |
5076 |
| -\tcode{*this}'s |
5077 |
| -error state. |
5078 |
| -(Exceptions thrown from |
5079 |
| -\tcode{basic_ios<>::clear()} |
5080 |
| -are not caught or rethrown.) |
5081 |
| -If |
5082 |
| -\tcode{(exceptions()\&badbit) != 0} |
5083 |
| -then the exception is rethrown. |
5084 |
| -It also counts the number of characters extracted. |
5085 |
| -If no exception has been thrown it ends |
5086 |
| -by storing the count in a member object |
5087 |
| -and returning the value specified. |
| 5035 | +\tcode{ios_base::badbit} is set in the local error state, |
| 5036 | +\tcode{*this}'s error state is set to the local error state, and |
| 5037 | +the exception is rethrown if \tcode{(exceptions() \& badbit) != 0}. |
| 5038 | +If no exception has been thrown it |
| 5039 | +stores the number of characters extracted |
| 5040 | +in a member object. |
| 5041 | +After extraction is done, the input function calls \tcode{setstate}, which |
| 5042 | +sets \tcode{*this}'s error state to the local error state, and |
| 5043 | +may throw an exception. |
5088 | 5044 | In any event the
|
5089 | 5045 | \tcode{sentry}
|
5090 | 5046 | object
|
|
5122 | 5078 | (as described above).
|
5123 | 5079 | After constructing a \tcode{sentry} object, extracts
|
5124 | 5080 | a character \tcode{c}, if one is available.
|
5125 |
| -Otherwise, the function calls |
5126 |
| -\tcode{setstate(failbit)}, |
5127 |
| -which may throw |
5128 |
| -\tcode{ios_base::failure}\iref{iostate.flags}. |
| 5081 | +Otherwise, |
| 5082 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 5083 | +before \tcode{setstate} is called. |
5129 | 5084 |
|
5130 | 5085 | \pnum
|
5131 | 5086 | \returns
|
|
5153 | 5108 | and
|
5154 | 5109 | \tcode{unsigned char}.
|
5155 | 5110 | \end{footnote}
|
5156 |
| -Otherwise, the function calls |
5157 |
| -\tcode{setstate(failbit)} |
5158 |
| -(which may throw |
5159 |
| -\tcode{ios_base::failure}\iref{iostate.flags}). |
| 5111 | +Otherwise, |
| 5112 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 5113 | +before \tcode{setstate} is called. |
5160 | 5114 |
|
5161 | 5115 | \pnum
|
5162 | 5116 | \returns
|
|
5189 | 5143 | \tcode{n} is less than one or \tcode{n - 1}
|
5190 | 5144 | characters are stored;
|
5191 | 5145 | \item
|
5192 |
| -end-of-file occurs on the input sequence |
5193 |
| -(in which case the function calls |
5194 |
| -\tcode{setstate(eofbit)}); |
| 5146 | +end-of-file occurs on the input sequence; |
5195 | 5147 | \item
|
5196 | 5148 | \tcode{traits::eq(c, delim)}
|
5197 | 5149 | for the next available input
|
|
5200 | 5152 | \end{itemize}
|
5201 | 5153 |
|
5202 | 5154 | \pnum
|
5203 |
| -If the function stores no characters, it calls |
5204 |
| -\tcode{setstate(failbit)} |
5205 |
| -(which may throw |
5206 |
| -\tcode{ios_base::\brk{}failure}\iref{iostate.flags}). |
| 5155 | +If the function stores no characters, |
| 5156 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 5157 | +before \tcode{setstate} is called. |
5207 | 5158 | In any case, if \tcode{n} is greater than zero it then stores a null character
|
5208 | 5159 | into the next successive location of the array.
|
5209 | 5160 |
|
|
5259 | 5210 | \end{itemize}
|
5260 | 5211 |
|
5261 | 5212 | \pnum
|
5262 |
| -If the function inserts no characters, it calls |
5263 |
| -\tcode{setstate(failbit)}, |
5264 |
| -which may throw |
5265 |
| -\tcode{ios_base::\brk{}failure}\iref{iostate.flags}. |
| 5213 | +If the function inserts no characters, |
| 5214 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 5215 | +before \tcode{setstate} is called. |
5266 | 5216 |
|
5267 | 5217 | \pnum
|
5268 | 5218 | \returns
|
|
5308 | 5258 | Characters are extracted and stored until one of the following occurs:
|
5309 | 5259 | \begin{enumerate}
|
5310 | 5260 | \item
|
5311 |
| -end-of-file occurs on the input sequence |
5312 |
| -(in which case the function calls |
5313 |
| -\tcode{setstate(eofbit)}); |
| 5261 | +end-of-file occurs on the input sequence; |
5314 | 5262 | \item
|
5315 | 5263 | \tcode{traits::eq(c, delim)}
|
5316 | 5264 | for the next available input
|
|
5340 | 5288 | \end{footnote}
|
5341 | 5289 |
|
5342 | 5290 | \pnum
|
5343 |
| -If the function extracts no characters, it calls |
5344 |
| -\tcode{setstate(failbit)} |
5345 |
| -(which may throw |
5346 |
| -\tcode{ios_base::\brk{}failure}\iref{iostate.flags}). |
| 5291 | +If the function extracts no characters, |
| 5292 | +\tcode{ios_base::failbit} is set in the input function's local error state |
| 5293 | +before \tcode{setstate} is called. |
5347 | 5294 | \begin{footnote}
|
5348 | 5295 | This implies an
|
5349 | 5296 | empty input line will not cause
|
|
0 commit comments