Przejdź do głównej zawartości

C++ named requirements: UnformattedInputFunction

Requirements

An UnformattedInputFunction 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 true, 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.
  • Checks the status of the sentry by calling sentry::operator bool(), which is equivalent to basic_ios::good.

    • If the operator returns false or sentry's constructor throws an exception:
      • Sets the number of extracted characters (gcount) in the input stream to zero.
      • If the function was called to write to an array of CharT, writes CharT() (the null character) to the first location of the array.
    • If the operator returns 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 during input, sets the number of extracted characters (gcount) in the input stream.
  • In any event, whether terminating by exception or returning, the sentry's destructor is called before leaving this function.

Standard library

The following standard library functions are UnformattedInputFunctions.

Defect reports

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

DRApplied toBehavior as publishedCorrect behavior
LWG 61C++98it was unclear whether throwing an exception because of setting eofbit and/or failbit will result in setting badbitexceptions thrown from basic_ios::clear are not caught or rethrown
LWG 160C++98the process of determining whether the exception caught is rethrown mentioned a non-existing function exception()corrected to exceptions()
LWG 243C++98the behavior when sentry::operator bool() returns false or the sentry object fails to be constructed was not specifiedspecified

C++ named requirements: UnformattedInputFunction

Requirements

An UnformattedInputFunction 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 true, 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.
  • Checks the status of the sentry by calling sentry::operator bool(), which is equivalent to basic_ios::good.

    • If the operator returns false or sentry's constructor throws an exception:
      • Sets the number of extracted characters (gcount) in the input stream to zero.
      • If the function was called to write to an array of CharT, writes CharT() (the null character) to the first location of the array.
    • If the operator returns 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 during input, sets the number of extracted characters (gcount) in the input stream.
  • In any event, whether terminating by exception or returning, the sentry's destructor is called before leaving this function.

Standard library

The following standard library functions are UnformattedInputFunctions.

Defect reports

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

DRApplied toBehavior as publishedCorrect behavior
LWG 61C++98it was unclear whether throwing an exception because of setting eofbit and/or failbit will result in setting badbitexceptions thrown from basic_ios::clear are not caught or rethrown
LWG 160C++98the process of determining whether the exception caught is rethrown mentioned a non-existing function exception()corrected to exceptions()
LWG 243C++98the behavior when sentry::operator bool() returns false or the sentry object fails to be constructed was not specifiedspecified