Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/FormattedInputFunction"

From cppreference.com
< cpp‎ | named req
m (T. Canens moved page cpp/concept/FormattedInputFunction to cpp/named req/FormattedInputFunction without leaving a redirect: Text replace - "cpp/concept" to "cpp/named req")
m (.)
 
(5 intermediate revisions by 3 users not shown)
Line 3: Line 3:
  
 
===Requirements===
 
===Requirements===
 +
A {{named req/core|FormattedInputFunction}} is a stream input function that performs the following:
  
A {{tt|FormattedInputFunction}} is a stream input function that performs the following:
+
* Constructs an object of type {{l2tt|cpp/io/basic_istream/sentry}} with automatic storage duration and with the {{tt|noskipws}} argument set to {{c|false}}, which performs the following:
 
+
:* if {{ltt|cpp/io/ios_base/iostate|eofbit}} or {{ltt|cpp/io/ios_base/iostate|badbit}} are set on the input stream, sets the {{tt|failbit}} as well, and if exceptions on {{tt|failbit}} are enabled in this input stream's [[cpp/io/basic_ios/exceptions|exception mask]] ({{c|1=(exceptions() & failbit) != 0}}), throws {{l2tt|cpp/io/ios_base/failure}}.
* Constructs an object of type {{l2tt|cpp/io/basic_istream/sentry}} with automatic storage duration and with the {{tt|noskipws}} argument set to {{c|false}}, which performs the following
+
:* flushes the tie()'d output stream, if applicable.
:* if {{ltt|cpp/io/ios_base/iostate|eofbit}} or {{ltt|cpp/io/ios_base/iostate|badbit}} are set on the input stream, sets the {{tt|failbit}} as well, and if exceptions on failbit are enabled in this input stream's exception mask, throws {{l2tt|cpp/io/ios_base/failure}}.
+
:* flushes the tie()'d output stream, if applicable
+
 
:* if {{tt|ios_base::skipws}} flag is set on this input stream, extracts and discards characters from the input stream until one of the following becomes true:
 
:* if {{tt|ios_base::skipws}} flag is set on this input stream, extracts and discards characters from the input stream until one of the following becomes true:
 
::* the next available character on the input stream is not a whitespace character, as tested by the {{lc|std::ctype}} facet of the locale currently imbued in this input stream. The non-whitespace character is not extracted.
 
::* the next available character on the input stream is not a whitespace character, as tested by the {{lc|std::ctype}} facet of the locale currently imbued in this input stream. The non-whitespace character is not extracted.
 
::* the end of the stream is reached, in which case {{tt|failbit}} and {{tt|eofbit}} are set and if the stream is on for exceptions on one of these bits, {{l2tt|cpp/io/ios_base/failure}} is thrown.
 
::* the end of the stream is reached, in which case {{tt|failbit}} and {{tt|eofbit}} are set and if the stream is on for exceptions on one of these bits, {{l2tt|cpp/io/ios_base/failure}} is thrown.
 
* Checks the status of the sentry by calling {{tt|sentry::operator bool()}}, which is equivalent to {{l2tt|cpp/io/basic_ios/good}}.
 
* Checks the status of the sentry by calling {{tt|sentry::operator bool()}}, which is equivalent to {{l2tt|cpp/io/basic_ios/good}}.
* If the sentry returned {{c|false}} or sentry's constructor threw an exception, no input takes place
+
* If the sentry returned {{c|false}} or sentry's constructor threw an exception, no input takes place.
 
* If the sentry returned {{c|true}}, performs the input as if by calling {{c|rdbuf()->sbumpc()}} or {{c|rdbuf()->sgetc()}}.
 
* If the sentry returned {{c|true}}, performs the input as if by calling {{c|rdbuf()->sbumpc()}} or {{c|rdbuf()->sgetc()}}.
:* if the end of the stream is reached (the call to {{c|rdbuf()->sbumpc()}} or {{c|rdbuf()->sgetc()}} returns {{c|Traits::eof()}}), sets {{tt|eofbit}}. If exceptions on eofbit are enabled in this stream's exception mask, throws {{l2tt|cpp/io/ios_base/failure}}.
+
:* if the end of the stream is reached (the call to {{c|rdbuf()->sbumpc()}} or {{c|rdbuf()->sgetc()}} returns {{c|Traits::eof()}}), sets {{tt|eofbit}}. If exceptions on {{tt|eofbit}} are enabled in this stream's [[cpp/io/basic_ios/exceptions|exception mask]] ({{c|1=(exceptions() & eofbit) != 0}}), throws {{l2tt|cpp/io/ios_base/failure}}.
:* if an exception is thrown during input, sets {{tt|badbit}} in the input stream. If exceptions on badbit are enabled in this stream's exception mask, the exception is also rethrown.
+
:* if an exception is thrown during input, sets {{tt|badbit}} in the input stream. If exceptions on {{tt|badbit}} are enabled in this stream's [[cpp/io/basic_ios/exceptions|exception mask]] ({{c|1=(exceptions() & badbit) != 0}}), the exception is also rethrown.
 
:* If no exception was thrown, returns {{c|*this}}.
 
:* If no exception was thrown, returns {{c|*this}}.
 
* In any event, whether terminating by exception or returning, the sentry's destructor is called before leaving this function.
 
* In any event, whether terminating by exception or returning, the sentry's destructor is called before leaving this function.
  
 
===Standard library===
 
===Standard library===
 
+
The following standard library functions are {{named req|FormattedInputFunction}}s.
The following standard library functions are {{concept|FormattedInputFunction}}s.
+
  
 
* {{l2tt|cpp/io/basic_istream/operator_gtgt|operator>>{{dsc small|(int, long, double, void*, bool)}}}}
 
* {{l2tt|cpp/io/basic_istream/operator_gtgt|operator>>{{dsc small|(int, long, double, void*, bool)}}}}
Line 31: Line 29:
 
* {{tt|operator>>}}, when called on the return value of {{lc|std::get_money}}
 
* {{tt|operator>>}}, when called on the return value of {{lc|std::get_money}}
  
{{langlinks|zh}}
+
===Defect reports===
 +
{{dr list begin}}
 +
{{dr list item|wg=lwg|dr=160|std=C++98|before=the process of determining whether the exception caught<br>is rethrown mentioned a non-existing function {{tt|exception()}}|after=corrected to {{ltt|cpp/io/basic_ios/exceptions|exceptions()}}}}
 +
{{dr list end}}
 +
 
 +
{{langlinks|ja|zh}}

Latest revision as of 07:10, 8 October 2023

 
 
C++ named requirements
 

[edit] Requirements

A FormattedInputFunction is a stream input function that performs the following:

  • Constructs an object of type basic_istream::sentry with automatic storage duration and with the noskipws argument set to false, which performs the following:
  • if eofbit or badbit are set on the input stream, sets the failbit as well, and if exceptions on failbit are enabled in this input stream's exception mask ((exceptions() & failbit) != 0), throws ios_base::failure.
  • flushes the tie()'d output stream, if applicable.
  • if ios_base::skipws flag is set on this input stream, extracts and discards characters from the input stream until one of the following becomes true:
  • the next available character on the input stream is not a whitespace character, as tested by the std::ctype facet of the locale currently imbued in this input stream. The non-whitespace character is not extracted.
  • the end of the stream is reached, in which case failbit and eofbit are set and if the stream is on for exceptions on one of these bits, ios_base::failure is thrown.
  • Checks the status of the sentry by calling sentry::operator bool(), which is equivalent to basic_ios::good.
  • If the sentry returned false or sentry's constructor threw an exception, no input takes place.
  • If the sentry returned true, performs the input as if by calling rdbuf()->sbumpc() or rdbuf()->sgetc().
  • if the end of the stream is reached (the call to rdbuf()->sbumpc() or rdbuf()->sgetc() returns Traits::eof()), sets eofbit. If exceptions on eofbit are enabled in this stream's exception mask ((exceptions() & eofbit) != 0), throws ios_base::failure.
  • if an exception is thrown during input, sets badbit in the input stream. If exceptions on badbit are enabled in this stream's exception mask ((exceptions() & badbit) != 0), the exception is also rethrown.
  • If no exception was thrown, returns *this.
  • In any event, whether terminating by exception or returning, the sentry's destructor is called before leaving this function.

[edit] Standard library

The following standard library functions are FormattedInputFunctions.

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 160 C++98 the process of determining whether the exception caught
is rethrown mentioned a non-existing function exception()
corrected to exceptions()