标签:boolean ret port mmu term protect util nts quick
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
加上了所有的头文件呀!那么你的代码…………还敢用么?
觉得这样太敷衍了,对比一下iostream
(已经宏展开)
// Standard iostream objects -*- C++ -*-
// Copyright (C) 1997-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file include/iostream
* This is a Standard C++ Library header.
*/
//
// ISO C++ 14882: 27.3 Standard iostream objects
//
#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1
#pragma GCC system_header
#include <bits/c++config.h>//注释:我还真没找到,就不展开了
// #include <istream>
// Input streams -*- C++ -*-
// Copyright (C) 1997-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
//
// ISO C++ 14882: 27.6.1 Input streams
//
/** @file include/istream
* This is a Standard C++ Library header.
*/
#ifndef _GLIBCXX_ISTREAM
#define _GLIBCXX_ISTREAM 1
#pragma GCC system_header
#include <ios>
#include <ostream>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @brief Template class basic_istream.
* @ingroup io
*
* @tparam _CharT Type of character stream.
* @tparam _Traits Traits for character type, defaults to
* char_traits<_CharT>.
*
* This is the base class for all input streams. It provides text
* formatting of all builtin types, and communicates with any class
* derived from basic_streambuf to do the actual input.
*/
template<typename _CharT, typename _Traits>
class basic_istream : virtual public basic_ios<_CharT, _Traits>
{
public:
// Types (inherited from basic_ios (27.4.4)):
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
// Non-standard Types:
typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
typedef basic_ios<_CharT, _Traits> __ios_type;
typedef basic_istream<_CharT, _Traits> __istream_type;
typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
__num_get_type;
typedef ctype<_CharT> __ctype_type;
protected:
// Data Members:
/**
* The number of characters extracted in the previous unformatted
* function; see gcount().
*/
streamsize _M_gcount;
public:
/**
* @brief Base constructor.
*
* This ctor is almost never called by the user directly, rather from
* derived classes' initialization lists, which pass a pointer to
* their own stream buffer.
*/
explicit
basic_istream(__streambuf_type* __sb)
: _M_gcount(streamsize(0))
{ this->init(__sb); }
/**
* @brief Base destructor.
*
* This does very little apart from providing a virtual base dtor.
*/
virtual
~basic_istream()
{ _M_gcount = streamsize(0); }
/// Safe prefix/suffix operations.
class sentry;
friend class sentry;
//@{
/**
* @brief Interface for manipulators.
*
* Manipulators such as @c std::ws and @c std::dec use these
* functions in constructs like
* <code>std::cin >> std::ws</code>.
* For more information, see the iomanip header.
*/
__istream_type&
operator>>(__istream_type& (*__pf)(__istream_type&))
{ return __pf(*this); }
__istream_type&
operator>>(__ios_type& (*__pf)(__ios_type&))
{
__pf(*this);
return *this;
}
__istream_type&
operator>>(ios_base& (*__pf)(ios_base&))
{
__pf(*this);
return *this;
}
//@}
//@{
/**
* @name Extractors
*
* All the @c operator>> functions (aka <em>formatted input
* functions</em>) have some common behavior. Each starts by
* constructing a temporary object of type std::basic_istream::sentry
* with the second argument (noskipws) set to false. This has several
* effects, concluding with the setting of a status flag; see the
* sentry documentation for more.
*
* If the sentry status is good, the function tries to extract
* whatever data is appropriate for the type of the argument.
*
* If an exception is thrown during extraction, ios_base::badbit
* will be turned on in the stream's error state without causing an
* ios_base::failure to be thrown. The original exception will then
* be rethrown.
*/
//@{
/**
* @brief Integer arithmetic extractors
* @param __n A variable of builtin integral type.
* @return @c *this if successful
*
* These functions use the stream's current locale (specifically, the
* @c num_get facet) to parse the input data.
*/
__istream_type&
operator>>(bool& __n)
{ return _M_extract(__n); }
__istream_type&
operator>>(short& __n);
__istream_type&
operator>>(unsigned short& __n)
{ return _M_extract(__n); }
__istream_type&
operator>>(int& __n);
__istream_type&
operator>>(unsigned int& __n)
{ return _M_extract(__n); }
__istream_type&
operator>>(long& __n)
{ return _M_extract(__n); }
__istream_type&
operator>>(unsigned long& __n)
{ return _M_extract(__n); }
#ifdef _GLIBCXX_USE_LONG_LONG
__istream_type&
operator>>(long long& __n)
{ return _M_extract(__n); }
__istream_type&
operator>>(unsigned long long& __n)
{ return _M_extract(__n); }
#endif
//@}
//@{
/**
* @brief Floating point arithmetic extractors
* @param __f A variable of builtin floating point type.
* @return @c *this if successful
*
* These functions use the stream's current locale (specifically, the
* @c num_get facet) to parse the input data.
*/
__istream_type&
operator>>(float& __f)
{ return _M_extract(__f); }
__istream_type&
operator>>(double& __f)
{ return _M_extract(__f); }
__istream_type&
operator>>(long double& __f)
{ return _M_extract(__f); }
//@}
/**
* @brief Basic arithmetic extractors
* @param __p A variable of pointer type.
* @return @c *this if successful
*
* These functions use the stream's current locale (specifically, the
* @c num_get facet) to parse the input data.
*/
__istream_type&
operator>>(void*& __p)
{ return _M_extract(__p); }
/**
* @brief Extracting into another streambuf.
* @param __sb A pointer to a streambuf
*
* This function behaves like one of the basic arithmetic extractors,
* in that it also constructs a sentry object and has the same error
* handling behavior.
*
* If @p __sb is NULL, the stream will set failbit in its error state.
*
* Characters are extracted from this stream and inserted into the
* @p __sb streambuf until one of the following occurs:
*
* - the input stream reaches end-of-file,
* - insertion into the output buffer fails (in this case, the
* character that would have been inserted is not extracted), or
* - an exception occurs (and in this case is caught)
*
* If the function inserts no characters, failbit is set.
*/
__istream_type&
operator>>(__streambuf_type* __sb);
//@}
// [27.6.1.3] unformatted input
/**
* @brief Character counting
* @return The number of characters extracted by the previous
* unformatted input function dispatched for this stream.
*/
streamsize
gcount() const
{ return _M_gcount; }
//@{
/**
* @name Unformatted Input Functions
*
* All the unformatted input functions have some common behavior.
* Each starts by constructing a temporary object of type
* std::basic_istream::sentry with the second argument (noskipws)
* set to true. This has several effects, concluding with the
* setting of a status flag; see the sentry documentation for more.
*
* If the sentry status is good, the function tries to extract
* whatever data is appropriate for the type of the argument.
*
* The number of characters extracted is stored for later retrieval
* by gcount().
*
* If an exception is thrown during extraction, ios_base::badbit
* will be turned on in the stream's error state without causing an
* ios_base::failure to be thrown. The original exception will then
* be rethrown.
*/
/**
* @brief Simple extraction.
* @return A character, or eof().
*
* Tries to extract a character. If none are available, sets failbit
* and returns traits::eof().
*/
int_type
get();
/**
* @brief Simple extraction.
* @param __c The character in which to store data.
* @return *this
*
* Tries to extract a character and store it in @a __c. If none are
* available, sets failbit and returns traits::eof().
*
* @note This function is not overloaded on signed char and
* unsigned char.
*/
__istream_type&
get(char_type& __c);
/**
* @brief Simple multiple-character extraction.
* @param __s Pointer to an array.
* @param __n Maximum number of characters to store in @a __s.
* @param __delim A "stop" character.
* @return *this
*
* Characters are extracted and stored into @a __s until one of the
* following happens:
*
* - @c __n-1 characters are stored
* - the input sequence reaches EOF
* - the next character equals @a __delim, in which case the character
* is not extracted
*
* If no characters are stored, failbit is set in the stream's error
* state.
*
* In any case, a null character is stored into the next location in
* the array.
*
* @note This function is not overloaded on signed char and
* unsigned char.
*/
__istream_type&
get(char_type* __s, streamsize __n, char_type __delim);
/**
* @brief Simple multiple-character extraction.
* @param __s Pointer to an array.
* @param __n Maximum number of characters to store in @a s.
* @return *this
*
* Returns @c get(__s,__n,widen('\\n')).
*/
__istream_type&
get(char_type* __s, streamsize __n)
{ return this->get(__s, __n, this->widen('\n')); }
/**
* @brief Extraction into another streambuf.
* @param __sb A streambuf in which to store data.
* @param __delim A "stop" character.
* @return *this
*
* Characters are extracted and inserted into @a __sb until one of the
* following happens:
*
* - the input sequence reaches EOF
* - insertion into the output buffer fails (in this case, the
* character that would have been inserted is not extracted)
* - the next character equals @a __delim (in this case, the character
* is not extracted)
* - an exception occurs (and in this case is caught)
*
* If no characters are stored, failbit is set in the stream's error
* state.
*/
__istream_type&
get(__streambuf_type& __sb, char_type __delim);
/**
* @brief Extraction into another streambuf.
* @param __sb A streambuf in which to store data.
* @return *this
*
* Returns @c get(__sb,widen('\\n')).
*/
__istream_type&
get(__streambuf_type& __sb)
{ return this->get(__sb, this->widen('\n')); }
/**
* @brief String extraction.
* @param __s A character array in which to store the data.
* @param __n Maximum number of characters to extract.
* @param __delim A "stop" character.
* @return *this
*
* Extracts and stores characters into @a __s until one of the
* following happens. Note that these criteria are required to be
* tested in the order listed here, to allow an input line to exactly
* fill the @a __s array without setting failbit.
*
* -# the input sequence reaches end-of-file, in which case eofbit
* is set in the stream error state
* -# the next character equals @c __delim, in which case the character
* is extracted (and therefore counted in @c gcount()) but not stored
* -# @c __n-1 characters are stored, in which case failbit is set
* in the stream error state
*
* If no characters are extracted, failbit is set. (An empty line of
* input should therefore not cause failbit to be set.)
*
* In any case, a null character is stored in the next location in
* the array.
*/
__istream_type&
getline(char_type* __s, streamsize __n, char_type __delim);
/**
* @brief String extraction.
* @param __s A character array in which to store the data.
* @param __n Maximum number of characters to extract.
* @return *this
*
* Returns @c getline(__s,__n,widen('\\n')).
*/
__istream_type&
getline(char_type* __s, streamsize __n)
{ return this->getline(__s, __n, this->widen('\n')); }
/**
* @brief Discarding characters
* @param __n Number of characters to discard.
* @param __delim A "stop" character.
* @return *this
*
* Extracts characters and throws them away until one of the
* following happens:
* - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
* characters are extracted
* - the input sequence reaches end-of-file
* - the next character equals @a __delim (in this case, the character
* is extracted); note that this condition will never occur if
* @a __delim equals @c traits::eof().
*
* NB: Provide three overloads, instead of the single function
* (with defaults) mandated by the Standard: this leads to a
* better performing implementation, while still conforming to
* the Standard.
*/
__istream_type&
ignore(streamsize __n, int_type __delim);
__istream_type&
ignore(streamsize __n);
__istream_type&
ignore();
/**
* @brief Looking ahead in the stream
* @return The next character, or eof().
*
* If, after constructing the sentry object, @c good() is false,
* returns @c traits::eof(). Otherwise reads but does not extract
* the next input character.
*/
int_type
peek();
/**
* @brief Extraction without delimiters.
* @param __s A character array.
* @param __n Maximum number of characters to store.
* @return *this
*
* If the stream state is @c good(), extracts characters and stores
* them into @a __s until one of the following happens:
* - @a __n characters are stored
* - the input sequence reaches end-of-file, in which case the error
* state is set to @c failbit|eofbit.
*
* @note This function is not overloaded on signed char and
* unsigned char.
*/
__istream_type&
read(char_type* __s, streamsize __n);
/**
* @brief Extraction until the buffer is exhausted, but no more.
* @param __s A character array.
* @param __n Maximum number of characters to store.
* @return The number of characters extracted.
*
* Extracts characters and stores them into @a __s depending on the
* number of characters remaining in the streambuf's buffer,
* @c rdbuf()->in_avail(), called @c A here:
* - if @c A @c == @c -1, sets eofbit and extracts no characters
* - if @c A @c == @c 0, extracts no characters
* - if @c A @c > @c 0, extracts @c min(A,n)
*
* The goal is to empty the current buffer, and to not request any
* more from the external input sequence controlled by the streambuf.
*/
streamsize
readsome(char_type* __s, streamsize __n);
/**
* @brief Unextracting a single character.
* @param __c The character to push back into the input stream.
* @return *this
*
* If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
*
* If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
* the error state.
*
* @note This function first clears eofbit. Since no characters
* are extracted, the next call to @c gcount() will return 0,
* as required by DR 60.
*/
__istream_type&
putback(char_type __c);
/**
* @brief Unextracting the previous character.
* @return *this
*
* If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
*
* If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
* the error state.
*
* @note This function first clears eofbit. Since no characters
* are extracted, the next call to @c gcount() will return 0,
* as required by DR 60.
*/
__istream_type&
unget();
/**
* @brief Synchronizing the stream buffer.
* @return 0 on success, -1 on failure
*
* If @c rdbuf() is a null pointer, returns -1.
*
* Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
* sets badbit and returns -1.
*
* Otherwise, returns 0.
*
* @note This function does not count the number of characters
* extracted, if any, and therefore does not affect the next
* call to @c gcount().
*/
int
sync();
/**
* @brief Getting the current read position.
* @return A file position object.
*
* If @c fail() is not false, returns @c pos_type(-1) to indicate
* failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
*
* @note This function does not count the number of characters
* extracted, if any, and therefore does not affect the next
* call to @c gcount(). At variance with putback, unget and
* seekg, eofbit is not cleared first.
*/
pos_type
tellg();
/**
* @brief Changing the current read position.
* @param __pos A file position object.
* @return *this
*
* If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If
* that function fails, sets failbit.
*
* @note This function first clears eofbit. It does not count the
* number of characters extracted, if any, and therefore does
* not affect the next call to @c gcount().
*/
__istream_type&
seekg(pos_type);
/**
* @brief Changing the current read position.
* @param __off A file offset object.
* @param __dir The direction in which to seek.
* @return *this
*
* If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
* If that function fails, sets failbit.
*
* @note This function first clears eofbit. It does not count the
* number of characters extracted, if any, and therefore does
* not affect the next call to @c gcount().
*/
__istream_type&
seekg(off_type, ios_base::seekdir);
//@}
protected:
basic_istream()
: _M_gcount(streamsize(0))
{ this->init(0); }
#if __cplusplus >= 201103L
basic_istream(const basic_istream&) = delete;
basic_istream(basic_istream&& __rhs)
: __ios_type(), _M_gcount(__rhs._M_gcount)
{
__ios_type::move(__rhs);
__rhs._M_gcount = 0;
}
// 27.7.3.3 Assign/swap
basic_istream& operator=(const basic_istream&) = delete;
basic_istream&
operator=(basic_istream&& __rhs)
{
swap(__rhs);
return *this;
}
void
swap(basic_istream& __rhs)
{
__ios_type::swap(__rhs);
std::swap(_M_gcount, __rhs._M_gcount);
}
#endif
template<typename _ValueT>
__istream_type&
_M_extract(_ValueT& __v);
};
/// Explicit specialization declarations, defined in src/istream.cc.
template<>
basic_istream<char>&
basic_istream<char>::
getline(char_type* __s, streamsize __n, char_type __delim);
template<>
basic_istream<char>&
basic_istream<char>::
ignore(streamsize __n);
template<>
basic_istream<char>&
basic_istream<char>::
ignore(streamsize __n, int_type __delim);
#ifdef _GLIBCXX_USE_WCHAR_T
template<>
basic_istream<wchar_t>&
basic_istream<wchar_t>::
getline(char_type* __s, streamsize __n, char_type __delim);
template<>
basic_istream<wchar_t>&
basic_istream<wchar_t>::
ignore(streamsize __n);
template<>
basic_istream<wchar_t>&
basic_istream<wchar_t>::
ignore(streamsize __n, int_type __delim);
#endif
/**
* @brief Performs setup work for input streams.
*
* Objects of this class are created before all of the standard
* extractors are run. It is responsible for <em>exception-safe
* prefix and suffix operations,</em> although only prefix actions
* are currently required by the standard.
*/
template<typename _CharT, typename _Traits>
class basic_istream<_CharT, _Traits>::sentry
{
// Data Members.
bool _M_ok;
public:
/// Easy access to dependent types.
typedef _Traits traits_type;
typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
typedef basic_istream<_CharT, _Traits> __istream_type;
typedef typename __istream_type::__ctype_type __ctype_type;
typedef typename _Traits::int_type __int_type;
/**
* @brief The constructor performs all the work.
* @param __is The input stream to guard.
* @param __noskipws Whether to consume whitespace or not.
*
* If the stream state is good (@a __is.good() is true), then the
* following actions are performed, otherwise the sentry state
* is false (<em>not okay</em>) and failbit is set in the
* stream state.
*
* The sentry's preparatory actions are:
*
* -# if the stream is tied to an output stream, @c is.tie()->flush()
* is called to synchronize the output sequence
* -# if @a __noskipws is false, and @c ios_base::skipws is set in
* @c is.flags(), the sentry extracts and discards whitespace
* characters from the stream. The currently imbued locale is
* used to determine whether each character is whitespace.
*
* If the stream state is still good, then the sentry state becomes
* true (@a okay).
*/
explicit
sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
/**
* @brief Quick status checking.
* @return The sentry state.
*
* For ease of use, sentries may be converted to booleans. The
* return value is that of the sentry state (true == okay).
*/
#if __cplusplus >= 201103L
explicit
#endif
operator bool() const
{ return _M_ok; }
};
//@{
/**
* @brief Character extractors
* @param __in An input stream.
* @param __c A character reference.
* @return in
*
* Behaves like one of the formatted arithmetic extractors described in
* std::basic_istream. After constructing a sentry object with good
* status, this function extracts a character (if one is available) and
* stores it in @a __c. Otherwise, sets failbit in the input stream.
*/
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
template<class _Traits>
inline basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
{ return (__in >> reinterpret_cast<char&>(__c)); }
template<class _Traits>
inline basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
{ return (__in >> reinterpret_cast<char&>(__c)); }
//@}
//@{
/**
* @brief Character string extractors
* @param __in An input stream.
* @param __s A pointer to a character array.
* @return __in
*
* Behaves like one of the formatted arithmetic extractors described in
* std::basic_istream. After constructing a sentry object with good
* status, this function extracts up to @c n characters and stores them
* into the array starting at @a __s. @c n is defined as:
*
* - if @c width() is greater than zero, @c n is width() otherwise
* - @c n is <em>the number of elements of the largest array of *
* - @c char_type that can store a terminating @c eos.</em>
* - [27.6.1.2.3]/6
*
* Characters are extracted and stored until one of the following happens:
* - @c n-1 characters are stored
* - EOF is reached
* - the next character is whitespace according to the current locale
* - the next character is a null byte (i.e., @c charT() )
*
* @c width(0) is then called for the input stream.
*
* If no characters are extracted, sets failbit.
*/
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
// Explicit specialization declaration, defined in src/istream.cc.
template<>
basic_istream<char>&
operator>>(basic_istream<char>& __in, char* __s);
template<class _Traits>
inline basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
{ return (__in >> reinterpret_cast<char*>(__s)); }
template<class _Traits>
inline basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
{ return (__in >> reinterpret_cast<char*>(__s)); }
//@}
/**
* @brief Template class basic_iostream
* @ingroup io
*
* @tparam _CharT Type of character stream.
* @tparam _Traits Traits for character type, defaults to
* char_traits<_CharT>.
*
* This class multiply inherits from the input and output stream classes
* simply to provide a single interface.
*/
template<typename _CharT, typename _Traits>
class basic_iostream
: public basic_istream<_CharT, _Traits>,
public basic_ostream<_CharT, _Traits>
{
public:
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 271. basic_iostream missing typedefs
// Types (inherited):
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
// Non-standard Types:
typedef basic_istream<_CharT, _Traits> __istream_type;
typedef basic_ostream<_CharT, _Traits> __ostream_type;
/**
* @brief Constructor does nothing.
*
* Both of the parent classes are initialized with the same
* streambuf pointer passed to this constructor.
*/
explicit
basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
: __istream_type(__sb), __ostream_type(__sb) { }
/**
* @brief Destructor does nothing.
*/
virtual
~basic_iostream() { }
protected:
basic_iostream()
: __istream_type(), __ostream_type() { }
#if __cplusplus >= 201103L
basic_iostream(const basic_iostream&) = delete;
basic_iostream(basic_iostream&& __rhs)
: __istream_type(std::move(__rhs)), __ostream_type(*this)
{ }
// 27.7.3.3 Assign/swap
basic_iostream& operator=(const basic_iostream&) = delete;
basic_iostream&
operator=(basic_iostream&& __rhs)
{
swap(__rhs);
return *this;
}
void
swap(basic_iostream& __rhs)
{ __istream_type::swap(__rhs); }
#endif
};
/**
* @brief Quick and easy way to eat whitespace
*
* This manipulator extracts whitespace characters, stopping when the
* next character is non-whitespace, or when the input sequence is empty.
* If the sequence is empty, @c eofbit is set in the stream, but not
* @c failbit.
*
* The current locale is used to distinguish whitespace characters.
*
* Example:
* @code
* MyClass mc;
*
* std::cin >> std::ws >> mc;
* @endcode
* will skip leading whitespace before calling operator>> on cin and your
* object. Note that the same effect can be achieved by creating a
* std::basic_istream::sentry inside your definition of operator>>.
*/
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
ws(basic_istream<_CharT, _Traits>& __is);
#if __cplusplus >= 201103L
// [27.7.1.6] Rvalue stream extraction
/**
* @brief Generic extractor for rvalue stream
* @param __is An input stream.
* @param __x A reference to the extraction target.
* @return is
*
* This is just a forwarding function to allow extraction from
* rvalue streams since they won't bind to the extractor functions
* that take an lvalue reference.
*/
template<typename _CharT, typename _Traits, typename _Tp>
inline basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
{
__is >> __x;
return __is;
}
#endif // C++11
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
// #include <bits/istream.tcc>
// istream classes -*- C++ -*-
// Copyright (C) 1997-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file bits/istream.tcc
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{istream}
*/
//
// ISO C++ 14882: 27.6.1 Input streams
//
#ifndef _ISTREAM_TCC
#define _ISTREAM_TCC 1
#pragma GCC system_header
#include <bits/cxxabi_forced.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>::sentry::
sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false)
{
ios_base::iostate __err = ios_base::goodbit;
if (__in.good())
{
if (__in.tie())
__in.tie()->flush();
if (!__noskip && bool(__in.flags() & ios_base::skipws))
{
const __int_type __eof = traits_type::eof();
__streambuf_type* __sb = __in.rdbuf();
__int_type __c = __sb->sgetc();
const __ctype_type& __ct = __check_facet(__in._M_ctype);
while (!traits_type::eq_int_type(__c, __eof)
&& __ct.is(ctype_base::space,
traits_type::to_char_type(__c)))
__c = __sb->snextc();
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 195. Should basic_istream::sentry's constructor ever
// set eofbit?
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
}
if (__in.good() && __err == ios_base::goodbit)
_M_ok = true;
else
{
__err |= ios_base::failbit;
__in.setstate(__err);
}
}
template<typename _CharT, typename _Traits>
template<typename _ValueT>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
_M_extract(_ValueT& __v)
{
sentry __cerb(*this, false);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __v);
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
operator>>(short& __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 118. basic_istream uses nonexistent num_get member functions.
sentry __cerb(*this, false);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
long __l;
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __l);
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 696. istream::operator>>(int&) broken.
if (__l < __gnu_cxx::__numeric_traits<short>::__min)
{
__err |= ios_base::failbit;
__n = __gnu_cxx::__numeric_traits<short>::__min;
}
else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
{
__err |= ios_base::failbit;
__n = __gnu_cxx::__numeric_traits<short>::__max;
}
else
__n = short(__l);
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
operator>>(int& __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 118. basic_istream uses nonexistent num_get member functions.
sentry __cerb(*this, false);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
long __l;
const __num_get_type& __ng = __check_facet(this->_M_num_get);
__ng.get(*this, 0, *this, __err, __l);
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 696. istream::operator>>(int&) broken.
if (__l < __gnu_cxx::__numeric_traits<int>::__min)
{
__err |= ios_base::failbit;
__n = __gnu_cxx::__numeric_traits<int>::__min;
}
else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
{
__err |= ios_base::failbit;
__n = __gnu_cxx::__numeric_traits<int>::__max;
}
else
__n = int(__l);
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
operator>>(__streambuf_type* __sbout)
{
ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, false);
if (__cerb && __sbout)
{
__try
{
bool __ineof;
if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
__err |= ios_base::failbit;
if (__ineof)
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::failbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::failbit); }
}
else if (!__sbout)
__err |= ios_base::failbit;
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
typename basic_istream<_CharT, _Traits>::int_type
basic_istream<_CharT, _Traits>::
get(void)
{
const int_type __eof = traits_type::eof();
int_type __c = __eof;
_M_gcount = 0;
ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
__try
{
__c = this->rdbuf()->sbumpc();
// 27.6.1.1 paragraph 3
if (!traits_type::eq_int_type(__c, __eof))
_M_gcount = 1;
else
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
}
if (!_M_gcount)
__err |= ios_base::failbit;
if (__err)
this->setstate(__err);
return __c;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
get(char_type& __c)
{
_M_gcount = 0;
ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
__try
{
const int_type __cb = this->rdbuf()->sbumpc();
// 27.6.1.1 paragraph 3
if (!traits_type::eq_int_type(__cb, traits_type::eof()))
{
_M_gcount = 1;
__c = traits_type::to_char_type(__cb);
}
else
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
}
if (!_M_gcount)
__err |= ios_base::failbit;
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
get(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
__try
{
const int_type __idelim = traits_type::to_int_type(__delim);
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
while (_M_gcount + 1 < __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __idelim))
{
*__s++ = traits_type::to_char_type(__c);
++_M_gcount;
__c = __sb->snextc();
}
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 243. get and getline when sentry reports failure.
if (__n > 0)
*__s = char_type();
if (!_M_gcount)
__err |= ios_base::failbit;
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
get(__streambuf_type& __sb, char_type __delim)
{
_M_gcount = 0;
ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
__try
{
const int_type __idelim = traits_type::to_int_type(__delim);
const int_type __eof = traits_type::eof();
__streambuf_type* __this_sb = this->rdbuf();
int_type __c = __this_sb->sgetc();
char_type __c2 = traits_type::to_char_type(__c);
while (!traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __idelim)
&& !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
{
++_M_gcount;
__c = __this_sb->snextc();
__c2 = traits_type::to_char_type(__c);
}
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
}
if (!_M_gcount)
__err |= ios_base::failbit;
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
getline(char_type* __s, streamsize __n, char_type __delim)
{
_M_gcount = 0;
ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this, true);
if (__cerb)
{
__try
{
const int_type __idelim = traits_type::to_int_type(__delim);
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
while (_M_gcount + 1 < __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __idelim))
{
*__s++ = traits_type::to_char_type(__c);
__c = __sb->snextc();
++_M_gcount;
}
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else
{
if (traits_type::eq_int_type(__c, __idelim))
{
__sb->sbumpc();
++_M_gcount;
}
else
__err |= ios_base::failbit;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 243. get and getline when sentry reports failure.
if (__n > 0)
*__s = char_type();
if (!_M_gcount)
__err |= ios_base::failbit;
if (__err)
this->setstate(__err);
return *this;
}
// We provide three overloads, since the first two are much simpler
// than the general case. Also, the latter two can thus adopt the
// same "batchy" strategy used by getline above.
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
ignore(void)
{
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
__err |= ios_base::eofbit;
else
_M_gcount = 1;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
ignore(streamsize __n)
{
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
// N.B. On LFS-enabled platforms streamsize is still 32 bits
// wide: if we want to implement the standard mandated behavior
// for n == max() (see 27.6.1.3/24) we are at risk of signed
// integer overflow: thus these contortions. Also note that,
// by definition, when more than 2G chars are actually ignored,
// _M_gcount (the return value of gcount, that is) cannot be
// really correct, being unavoidably too small.
bool __large_ignore = false;
while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof))
{
++_M_gcount;
__c = __sb->snextc();
}
if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
&& !traits_type::eq_int_type(__c, __eof))
{
_M_gcount =
__gnu_cxx::__numeric_traits<streamsize>::__min;
__large_ignore = true;
}
else
break;
}
if (__large_ignore)
_M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
ignore(streamsize __n, int_type __delim)
{
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb && __n > 0)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc();
// See comment above.
bool __large_ignore = false;
while (true)
{
while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{
++_M_gcount;
__c = __sb->snextc();
}
if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
&& !traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __delim))
{
_M_gcount =
__gnu_cxx::__numeric_traits<streamsize>::__min;
__large_ignore = true;
}
else
break;
}
if (__large_ignore)
_M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
if (traits_type::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else if (traits_type::eq_int_type(__c, __delim))
{
if (_M_gcount
< __gnu_cxx::__numeric_traits<streamsize>::__max)
++_M_gcount;
__sb->sbumpc();
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
typename basic_istream<_CharT, _Traits>::int_type
basic_istream<_CharT, _Traits>::
peek(void)
{
int_type __c = traits_type::eof();
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
__c = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__c, traits_type::eof()))
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return __c;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
read(char_type* __s, streamsize __n)
{
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
_M_gcount = this->rdbuf()->sgetn(__s, __n);
if (_M_gcount != __n)
__err |= (ios_base::eofbit | ios_base::failbit);
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
streamsize
basic_istream<_CharT, _Traits>::
readsome(char_type* __s, streamsize __n)
{
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
// Cannot compare int_type with streamsize generically.
const streamsize __num = this->rdbuf()->in_avail();
if (__num > 0)
_M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
else if (__num == -1)
__err |= ios_base::eofbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return _M_gcount;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
putback(char_type __c)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 60. What is a formatted input function?
_M_gcount = 0;
// Clear eofbit per N3168.
this->clear(this->rdstate() & ~ios_base::eofbit);
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
if (!__sb
|| traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
__err |= ios_base::badbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
unget(void)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 60. What is a formatted input function?
_M_gcount = 0;
// Clear eofbit per N3168.
this->clear(this->rdstate() & ~ios_base::eofbit);
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf();
if (!__sb
|| traits_type::eq_int_type(__sb->sungetc(), __eof))
__err |= ios_base::badbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
int
basic_istream<_CharT, _Traits>::
sync(void)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
int __ret = -1;
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
__streambuf_type* __sb = this->rdbuf();
if (__sb)
{
if (__sb->pubsync() == -1)
__err |= ios_base::badbit;
else
__ret = 0;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return __ret;
}
template<typename _CharT, typename _Traits>
typename basic_istream<_CharT, _Traits>::pos_type
basic_istream<_CharT, _Traits>::
tellg(void)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
pos_type __ret = pos_type(-1);
sentry __cerb(*this, true);
if (__cerb)
{
__try
{
if (!this->fail())
__ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
ios_base::in);
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
}
return __ret;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
seekg(pos_type __pos)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
// Clear eofbit per N3168.
this->clear(this->rdstate() & ~ios_base::eofbit);
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
{
// 136. seekp, seekg setting wrong streams?
const pos_type __p = this->rdbuf()->pubseekpos(__pos,
ios_base::in);
// 129. Need error indication from seekp() and seekg()
if (__p == pos_type(off_type(-1)))
__err |= ios_base::failbit;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::
seekg(off_type __off, ios_base::seekdir __dir)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR60. Do not change _M_gcount.
// Clear eofbit per N3168.
this->clear(this->rdstate() & ~ios_base::eofbit);
sentry __cerb(*this, true);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
{
// 136. seekp, seekg setting wrong streams?
const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
ios_base::in);
// 129. Need error indication from seekp() and seekg()
if (__p == pos_type(off_type(-1)))
__err |= ios_base::failbit;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
// 27.6.1.2.3 Character extraction templates
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
{
typedef basic_istream<_CharT, _Traits> __istream_type;
typedef typename __istream_type::int_type __int_type;
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const __int_type __cb = __in.rdbuf()->sbumpc();
if (!_Traits::eq_int_type(__cb, _Traits::eof()))
__c = _Traits::to_char_type(__cb);
else
__err |= (ios_base::eofbit | ios_base::failbit);
}
__catch(__cxxabiv1::__forced_unwind&)
{
__in._M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ __in._M_setstate(ios_base::badbit); }
if (__err)
__in.setstate(__err);
}
return __in;
}
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
{
typedef basic_istream<_CharT, _Traits> __istream_type;
typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
typedef typename _Traits::int_type int_type;
typedef _CharT char_type;
typedef ctype<_CharT> __ctype_type;
streamsize __extracted = 0;
ios_base::iostate __err = ios_base::goodbit;
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
__try
{
// Figure out how many characters to extract.
streamsize __num = __in.width();
if (__num <= 0)
__num = __gnu_cxx::__numeric_traits<streamsize>::__max;
const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
const int_type __eof = _Traits::eof();
__streambuf_type* __sb = __in.rdbuf();
int_type __c = __sb->sgetc();
while (__extracted < __num - 1
&& !_Traits::eq_int_type(__c, __eof)
&& !__ct.is(ctype_base::space,
_Traits::to_char_type(__c)))
{
*__s++ = _Traits::to_char_type(__c);
++__extracted;
__c = __sb->snextc();
}
if (_Traits::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 68. Extractors for char* should store null at end
*__s = char_type();
__in.width(0);
}
__catch(__cxxabiv1::__forced_unwind&)
{
__in._M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ __in._M_setstate(ios_base::badbit); }
}
if (!__extracted)
__err |= ios_base::failbit;
if (__err)
__in.setstate(__err);
return __in;
}
// 27.6.1.4 Standard basic_istream manipulators
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
ws(basic_istream<_CharT, _Traits>& __in)
{
typedef basic_istream<_CharT, _Traits> __istream_type;
typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
typedef typename __istream_type::int_type __int_type;
typedef ctype<_CharT> __ctype_type;
const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
const __int_type __eof = _Traits::eof();
__streambuf_type* __sb = __in.rdbuf();
__int_type __c = __sb->sgetc();
while (!_Traits::eq_int_type(__c, __eof)
&& __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
__c = __sb->snextc();
if (_Traits::eq_int_type(__c, __eof))
__in.setstate(ios_base::eofbit);
return __in;
}
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
#if _GLIBCXX_EXTERN_TEMPLATE
extern template class basic_istream<char>;
extern template istream& ws(istream&);
extern template istream& operator>>(istream&, char&);
extern template istream& operator>>(istream&, char*);
extern template istream& operator>>(istream&, unsigned char&);
extern template istream& operator>>(istream&, signed char&);
extern template istream& operator>>(istream&, unsigned char*);
extern template istream& operator>>(istream&, signed char*);
extern template istream& istream::_M_extract(unsigned short&);
extern template istream& istream::_M_extract(unsigned int&);
extern template istream& istream::_M_extract(long&);
extern template istream& istream::_M_extract(unsigned long&);
extern template istream& istream::_M_extract(bool&);
#ifdef _GLIBCXX_USE_LONG_LONG
extern template istream& istream::_M_extract(long long&);
extern template istream& istream::_M_extract(unsigned long long&);
#endif
extern template istream& istream::_M_extract(float&);
extern template istream& istream::_M_extract(double&);
extern template istream& istream::_M_extract(long double&);
extern template istream& istream::_M_extract(void*&);
extern template class basic_iostream<char>;
#ifdef _GLIBCXX_USE_WCHAR_T
extern template class basic_istream<wchar_t>;
extern template wistream& ws(wistream&);
extern template wistream& operator>>(wistream&, wchar_t&);
extern template wistream& operator>>(wistream&, wchar_t*);
extern template wistream& wistream::_M_extract(unsigned short&);
extern template wistream& wistream::_M_extract(unsigned int&);
extern template wistream& wistream::_M_extract(long&);
extern template wistream& wistream::_M_extract(unsigned long&);
extern template wistream& wistream::_M_extract(bool&);
#ifdef _GLIBCXX_USE_LONG_LONG
extern template wistream& wistream::_M_extract(long long&);
extern template wistream& wistream::_M_extract(unsigned long long&);
#endif
extern template wistream& wistream::_M_extract(float&);
extern template wistream& wistream::_M_extract(double&);
extern template wistream& wistream::_M_extract(long double&);
extern template wistream& wistream::_M_extract(void*&);
extern template class basic_iostream<wchar_t>;
#endif
#endif
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif
#endif /* _GLIBCXX_ISTREAM */
// #include <ostream>
// Output streams -*- C++ -*-
// Copyright (C) 1997-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file include/ostream
* This is a Standard C++ Library header.
*/
//
// ISO C++ 14882: 27.6.2 Output streams
//
#ifndef _GLIBCXX_OSTREAM
#define _GLIBCXX_OSTREAM 1
#pragma GCC system_header
#include <ios>
#include <bits/ostream_insert.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @brief Template class basic_ostream.
* @ingroup io
*
* @tparam _CharT Type of character stream.
* @tparam _Traits Traits for character type, defaults to
* char_traits<_CharT>.
*
* This is the base class for all output streams. It provides text
* formatting of all builtin types, and communicates with any class
* derived from basic_streambuf to do the actual output.
*/
template<typename _CharT, typename _Traits>
class basic_ostream : virtual public basic_ios<_CharT, _Traits>
{
public:
// Types (inherited from basic_ios):
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
// Non-standard Types:
typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
typedef basic_ios<_CharT, _Traits> __ios_type;
typedef basic_ostream<_CharT, _Traits> __ostream_type;
typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> >
__num_put_type;
typedef ctype<_CharT> __ctype_type;
/**
* @brief Base constructor.
*
* This ctor is almost never called by the user directly, rather from
* derived classes' initialization lists, which pass a pointer to
* their own stream buffer.
*/
explicit
basic_ostream(__streambuf_type* __sb)
{ this->init(__sb); }
/**
* @brief Base destructor.
*
* This does very little apart from providing a virtual base dtor.
*/
virtual
~basic_ostream() { }
/// Safe prefix/suffix operations.
class sentry;
friend class sentry;
//@{
/**
* @brief Interface for manipulators.
*
* Manipulators such as @c std::endl and @c std::hex use these
* functions in constructs like "std::cout << std::endl". For more
* information, see the iomanip header.
*/
__ostream_type&
operator<<(__ostream_type& (*__pf)(__ostream_type&))
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// The inserters for manipulators are *not* formatted output functions.
return __pf(*this);
}
__ostream_type&
operator<<(__ios_type& (*__pf)(__ios_type&))
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// The inserters for manipulators are *not* formatted output functions.
__pf(*this);
return *this;
}
__ostream_type&
operator<<(ios_base& (*__pf) (ios_base&))
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// The inserters for manipulators are *not* formatted output functions.
__pf(*this);
return *this;
}
//@}
//@{
/**
* @name Inserters
*
* All the @c operator<< functions (aka <em>formatted output
* functions</em>) have some common behavior. Each starts by
* constructing a temporary object of type std::basic_ostream::sentry.
* This can have several effects, concluding with the setting of a
* status flag; see the sentry documentation for more.
*
* If the sentry status is good, the function tries to generate
* whatever data is appropriate for the type of the argument.
*
* If an exception is thrown during insertion, ios_base::badbit
* will be turned on in the stream's error state without causing an
* ios_base::failure to be thrown. The original exception will then
* be rethrown.
*/
//@{
/**
* @brief Integer arithmetic inserters
* @param __n A variable of builtin integral type.
* @return @c *this if successful
*
* These functions use the stream's current locale (specifically, the
* @c num_get facet) to perform numeric formatting.
*/
__ostream_type&
operator<<(long __n)
{ return _M_insert(__n); }
__ostream_type&
operator<<(unsigned long __n)
{ return _M_insert(__n); }
__ostream_type&
operator<<(bool __n)
{ return _M_insert(__n); }
__ostream_type&
operator<<(short __n);
__ostream_type&
operator<<(unsigned short __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 117. basic_ostream uses nonexistent num_put member functions.
return _M_insert(static_cast<unsigned long>(__n));
}
__ostream_type&
operator<<(int __n);
__ostream_type&
operator<<(unsigned int __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 117. basic_ostream uses nonexistent num_put member functions.
return _M_insert(static_cast<unsigned long>(__n));
}
#ifdef _GLIBCXX_USE_LONG_LONG
__ostream_type&
operator<<(long long __n)
{ return _M_insert(__n); }
__ostream_type&
operator<<(unsigned long long __n)
{ return _M_insert(__n); }
#endif
//@}
//@{
/**
* @brief Floating point arithmetic inserters
* @param __f A variable of builtin floating point type.
* @return @c *this if successful
*
* These functions use the stream's current locale (specifically, the
* @c num_get facet) to perform numeric formatting.
*/
__ostream_type&
operator<<(double __f)
{ return _M_insert(__f); }
__ostream_type&
operator<<(float __f)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 117. basic_ostream uses nonexistent num_put member functions.
return _M_insert(static_cast<double>(__f));
}
__ostream_type&
operator<<(long double __f)
{ return _M_insert(__f); }
//@}
/**
* @brief Pointer arithmetic inserters
* @param __p A variable of pointer type.
* @return @c *this if successful
*
* These functions use the stream's current locale (specifically, the
* @c num_get facet) to perform numeric formatting.
*/
__ostream_type&
operator<<(const void* __p)
{ return _M_insert(__p); }
/**
* @brief Extracting from another streambuf.
* @param __sb A pointer to a streambuf
*
* This function behaves like one of the basic arithmetic extractors,
* in that it also constructs a sentry object and has the same error
* handling behavior.
*
* If @p __sb is NULL, the stream will set failbit in its error state.
*
* Characters are extracted from @p __sb and inserted into @c *this
* until one of the following occurs:
*
* - the input stream reaches end-of-file,
* - insertion into the output sequence fails (in this case, the
* character that would have been inserted is not extracted), or
* - an exception occurs while getting a character from @p __sb, which
* sets failbit in the error state
*
* If the function inserts no characters, failbit is set.
*/
__ostream_type&
operator<<(__streambuf_type* __sb);
//@}
//@{
/**
* @name Unformatted Output Functions
*
* All the unformatted output functions have some common behavior.
* Each starts by constructing a temporary object of type
* std::basic_ostream::sentry. This has several effects, concluding
* with the setting of a status flag; see the sentry documentation
* for more.
*
* If the sentry status is good, the function tries to generate
* whatever data is appropriate for the type of the argument.
*
* If an exception is thrown during insertion, ios_base::badbit
* will be turned on in the stream's error state. If badbit is on in
* the stream's exceptions mask, the exception will be rethrown
* without completing its actions.
*/
/**
* @brief Simple insertion.
* @param __c The character to insert.
* @return *this
*
* Tries to insert @p __c.
*
* @note This function is not overloaded on signed char and
* unsigned char.
*/
__ostream_type&
put(char_type __c);
/**
* @brief Core write functionality, without sentry.
* @param __s The array to insert.
* @param __n Maximum number of characters to insert.
*/
void
_M_write(const char_type* __s, streamsize __n)
{
const streamsize __put = this->rdbuf()->sputn(__s, __n);
if (__put != __n)
this->setstate(ios_base::badbit);
}
/**
* @brief Character string insertion.
* @param __s The array to insert.
* @param __n Maximum number of characters to insert.
* @return *this
*
* Characters are copied from @p __s and inserted into the stream until
* one of the following happens:
*
* - @p __n characters are inserted
* - inserting into the output sequence fails (in this case, badbit
* will be set in the stream's error state)
*
* @note This function is not overloaded on signed char and
* unsigned char.
*/
__ostream_type&
write(const char_type* __s, streamsize __n);
//@}
/**
* @brief Synchronizing the stream buffer.
* @return *this
*
* If @c rdbuf() is a null pointer, changes nothing.
*
* Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
* sets badbit.
*/
__ostream_type&
flush();
/**
* @brief Getting the current write position.
* @return A file position object.
*
* If @c fail() is not false, returns @c pos_type(-1) to indicate
* failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,out).
*/
pos_type
tellp();
/**
* @brief Changing the current write position.
* @param __pos A file position object.
* @return *this
*
* If @c fail() is not true, calls @c rdbuf()->pubseekpos(pos). If
* that function fails, sets failbit.
*/
__ostream_type&
seekp(pos_type);
/**
* @brief Changing the current write position.
* @param __off A file offset object.
* @param __dir The direction in which to seek.
* @return *this
*
* If @c fail() is not true, calls @c rdbuf()->pubseekoff(off,dir).
* If that function fails, sets failbit.
*/
__ostream_type&
seekp(off_type, ios_base::seekdir);
protected:
basic_ostream()
{ this->init(0); }
#if __cplusplus >= 201103L
// Non-standard constructor that does not call init()
basic_ostream(basic_iostream<_CharT, _Traits>&) { }
basic_ostream(const basic_ostream&) = delete;
basic_ostream(basic_ostream&& __rhs)
: __ios_type()
{ __ios_type::move(__rhs); }
// 27.7.3.3 Assign/swap
basic_ostream& operator=(const basic_ostream&) = delete;
basic_ostream&
operator=(basic_ostream&& __rhs)
{
swap(__rhs);
return *this;
}
void
swap(basic_ostream& __rhs)
{ __ios_type::swap(__rhs); }
#endif
template<typename _ValueT>
__ostream_type&
_M_insert(_ValueT __v);
};
/**
* @brief Performs setup work for output streams.
*
* Objects of this class are created before all of the standard
* inserters are run. It is responsible for <em>exception-safe prefix and
* suffix operations</em>.
*/
template <typename _CharT, typename _Traits>
class basic_ostream<_CharT, _Traits>::sentry
{
// Data Members.
bool _M_ok;
basic_ostream<_CharT, _Traits>& _M_os;
public:
/**
* @brief The constructor performs preparatory work.
* @param __os The output stream to guard.
*
* If the stream state is good (@a __os.good() is true), then if the
* stream is tied to another output stream, @c is.tie()->flush()
* is called to synchronize the output sequences.
*
* If the stream state is still good, then the sentry state becomes
* true (@a okay).
*/
explicit
sentry(basic_ostream<_CharT, _Traits>& __os);
/**
* @brief Possibly flushes the stream.
*
* If @c ios_base::unitbuf is set in @c os.flags(), and
* @c std::uncaught_exception() is true, the sentry destructor calls
* @c flush() on the output stream.
*/
~sentry()
{
// XXX MT
if (bool(_M_os.flags() & ios_base::unitbuf) && !uncaught_exception())
{
// Can't call flush directly or else will get into recursive lock.
if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
_M_os.setstate(ios_base::badbit);
}
}
/**
* @brief Quick status checking.
* @return The sentry state.
*
* For ease of use, sentries may be converted to booleans. The
* return value is that of the sentry state (true == okay).
*/
#if __cplusplus >= 201103L
explicit
#endif
operator bool() const
{ return _M_ok; }
};
//@{
/**
* @brief Character inserters
* @param __out An output stream.
* @param __c A character.
* @return out
*
* Behaves like one of the formatted arithmetic inserters described in
* std::basic_ostream. After constructing a sentry object with good
* status, this function inserts a single character and any required
* padding (as determined by [22.2.2.2.2]). @c __out.width(0) is then
* called.
*
* If @p __c is of type @c char and the character type of the stream is not
* @c char, the character is widened before insertion.
*/
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
{ return __ostream_insert(__out, &__c, 1); }
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
{ return (__out << __out.widen(__c)); }
// Specialization
template <class _Traits>
inline basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __out, char __c)
{ return __ostream_insert(__out, &__c, 1); }
// Signed and unsigned
template<class _Traits>
inline basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
{ return (__out << static_cast<char>(__c)); }
template<class _Traits>
inline basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
{ return (__out << static_cast<char>(__c)); }
//@}
//@{
/**
* @brief String inserters
* @param __out An output stream.
* @param __s A character string.
* @return out
* @pre @p __s must be a non-NULL pointer
*
* Behaves like one of the formatted arithmetic inserters described in
* std::basic_ostream. After constructing a sentry object with good
* status, this function inserts @c traits::length(__s) characters starting
* at @p __s, widened if necessary, followed by any required padding (as
* determined by [22.2.2.2.2]). @c __out.width(0) is then called.
*/
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
{
if (!__s)
__out.setstate(ios_base::badbit);
else
__ostream_insert(__out, __s,
static_cast<streamsize>(_Traits::length(__s)));
return __out;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits> &
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
// Partial specializations
template<class _Traits>
inline basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
{
if (!__s)
__out.setstate(ios_base::badbit);
else
__ostream_insert(__out, __s,
static_cast<streamsize>(_Traits::length(__s)));
return __out;
}
// Signed and unsigned
template<class _Traits>
inline basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
{ return (__out << reinterpret_cast<const char*>(__s)); }
template<class _Traits>
inline basic_ostream<char, _Traits> &
operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
{ return (__out << reinterpret_cast<const char*>(__s)); }
//@}
// Standard basic_ostream manipulators
/**
* @brief Write a newline and flush the stream.
*
* This manipulator is often mistakenly used when a simple newline is
* desired, leading to poor buffering performance. See
* https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html#io.streambuf.buffering
* for more on this subject.
*/
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
endl(basic_ostream<_CharT, _Traits>& __os)
{ return flush(__os.put(__os.widen('\n'))); }
/**
* @brief Write a null character into the output sequence.
*
* <em>Null character</em> is @c CharT() by definition. For CharT
* of @c char, this correctly writes the ASCII @c NUL character
* string terminator.
*/
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
ends(basic_ostream<_CharT, _Traits>& __os)
{ return __os.put(_CharT()); }
/**
* @brief Flushes the output stream.
*
* This manipulator simply calls the stream's @c flush() member function.
*/
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
flush(basic_ostream<_CharT, _Traits>& __os)
{ return __os.flush(); }
#if __cplusplus >= 201103L
/**
* @brief Generic inserter for rvalue stream
* @param __os An input stream.
* @param __x A reference to the object being inserted.
* @return os
*
* This is just a forwarding function to allow insertion to
* rvalue streams since they won't bind to the inserter functions
* that take an lvalue reference.
*/
template<typename _CharT, typename _Traits, typename _Tp>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
{
__os << __x;
return __os;
}
#endif // C++11
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
// #include <bits/ostream.tcc>
// ostream classes -*- C++ -*-
// Copyright (C) 1997-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file bits/ostream.tcc
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{ostream}
*/
//
// ISO C++ 14882: 27.6.2 Output streams
//
#ifndef _OSTREAM_TCC
#define _OSTREAM_TCC 1
#pragma GCC system_header
#include <bits/cxxabi_forced.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>::sentry::
sentry(basic_ostream<_CharT, _Traits>& __os)
: _M_ok(false), _M_os(__os)
{
// XXX MT
if (__os.tie() && __os.good())
__os.tie()->flush();
if (__os.good())
_M_ok = true;
else
__os.setstate(ios_base::failbit);
}
template<typename _CharT, typename _Traits>
template<typename _ValueT>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
_M_insert(_ValueT __v)
{
sentry __cerb(*this);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const __num_put_type& __np = __check_facet(this->_M_num_put);
if (__np.put(*this, *this, this->fill(), __v).failed())
__err |= ios_base::badbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
operator<<(short __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 117. basic_ostream uses nonexistent num_put member functions.
const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
if (__fmt == ios_base::oct || __fmt == ios_base::hex)
return _M_insert(static_cast<long>(static_cast<unsigned short>(__n)));
else
return _M_insert(static_cast<long>(__n));
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
operator<<(int __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 117. basic_ostream uses nonexistent num_put member functions.
const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
if (__fmt == ios_base::oct || __fmt == ios_base::hex)
return _M_insert(static_cast<long>(static_cast<unsigned int>(__n)));
else
return _M_insert(static_cast<long>(__n));
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
operator<<(__streambuf_type* __sbin)
{
ios_base::iostate __err = ios_base::goodbit;
sentry __cerb(*this);
if (__cerb && __sbin)
{
__try
{
if (!__copy_streambufs(__sbin, this->rdbuf()))
__err |= ios_base::failbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::failbit); }
}
else if (!__sbin)
__err |= ios_base::badbit;
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
put(char_type __c)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// basic_ostream::put(char_type) is an unformatted output function.
// DR 63. Exception-handling policy for unformatted output.
// Unformatted output functions should catch exceptions thrown
// from streambuf members.
sentry __cerb(*this);
if (__cerb)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
const int_type __put = this->rdbuf()->sputc(__c);
if (traits_type::eq_int_type(__put, traits_type::eof()))
__err |= ios_base::badbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
write(const _CharT* __s, streamsize __n)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// basic_ostream::write(const char_type*, streamsize) is an
// unformatted output function.
// DR 63. Exception-handling policy for unformatted output.
// Unformatted output functions should catch exceptions thrown
// from streambuf members.
sentry __cerb(*this);
if (__cerb)
{
__try
{ _M_write(__s, __n); }
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
}
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
flush()
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 60. What is a formatted input function?
// basic_ostream::flush() is *not* an unformatted output function.
ios_base::iostate __err = ios_base::goodbit;
__try
{
if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
__err |= ios_base::badbit;
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
typename basic_ostream<_CharT, _Traits>::pos_type
basic_ostream<_CharT, _Traits>::
tellp()
{
pos_type __ret = pos_type(-1);
__try
{
if (!this->fail())
__ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
return __ret;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
seekp(pos_type __pos)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
const pos_type __p = this->rdbuf()->pubseekpos(__pos,
ios_base::out);
// 129. Need error indication from seekp() and seekg()
if (__p == pos_type(off_type(-1)))
__err |= ios_base::failbit;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::
seekp(off_type __off, ios_base::seekdir __dir)
{
ios_base::iostate __err = ios_base::goodbit;
__try
{
if (!this->fail())
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 136. seekp, seekg setting wrong streams?
const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
ios_base::out);
// 129. Need error indication from seekp() and seekg()
if (__p == pos_type(off_type(-1)))
__err |= ios_base::failbit;
}
}
__catch(__cxxabiv1::__forced_unwind&)
{
this->_M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ this->_M_setstate(ios_base::badbit); }
if (__err)
this->setstate(__err);
return *this;
}
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
{
if (!__s)
__out.setstate(ios_base::badbit);
else
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 167. Improper use of traits_type::length()
const size_t __clen = char_traits<char>::length(__s);
__try
{
struct __ptr_guard
{
_CharT *__p;
__ptr_guard (_CharT *__ip): __p(__ip) { }
~__ptr_guard() { delete[] __p; }
_CharT* __get() { return __p; }
} __pg (new _CharT[__clen]);
_CharT *__ws = __pg.__get();
for (size_t __i = 0; __i < __clen; ++__i)
__ws[__i] = __out.widen(__s[__i]);
__ostream_insert(__out, __ws, __clen);
}
__catch(__cxxabiv1::__forced_unwind&)
{
__out._M_setstate(ios_base::badbit);
__throw_exception_again;
}
__catch(...)
{ __out._M_setstate(ios_base::badbit); }
}
return __out;
}
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
#if _GLIBCXX_EXTERN_TEMPLATE
extern template class basic_ostream<char>;
extern template ostream& endl(ostream&);
extern template ostream& ends(ostream&);
extern template ostream& flush(ostream&);
extern template ostream& operator<<(ostream&, char);
extern template ostream& operator<<(ostream&, unsigned char);
extern template ostream& operator<<(ostream&, signed char);
extern template ostream& operator<<(ostream&, const char*);
extern template ostream& operator<<(ostream&, const unsigned char*);
extern template ostream& operator<<(ostream&, const signed char*);
extern template ostream& ostream::_M_insert(long);
extern template ostream& ostream::_M_insert(unsigned long);
extern template ostream& ostream::_M_insert(bool);
#ifdef _GLIBCXX_USE_LONG_LONG
extern template ostream& ostream::_M_insert(long long);
extern template ostream& ostream::_M_insert(unsigned long long);
#endif
extern template ostream& ostream::_M_insert(double);
extern template ostream& ostream::_M_insert(long double);
extern template ostream& ostream::_M_insert(const void*);
#ifdef _GLIBCXX_USE_WCHAR_T
extern template class basic_ostream<wchar_t>;
extern template wostream& endl(wostream&);
extern template wostream& ends(wostream&);
extern template wostream& flush(wostream&);
extern template wostream& operator<<(wostream&, wchar_t);
extern template wostream& operator<<(wostream&, char);
extern template wostream& operator<<(wostream&, const wchar_t*);
extern template wostream& operator<<(wostream&, const char*);
extern template wostream& wostream::_M_insert(long);
extern template wostream& wostream::_M_insert(unsigned long);
extern template wostream& wostream::_M_insert(bool);
#ifdef _GLIBCXX_USE_LONG_LONG
extern template wostream& wostream::_M_insert(long long);
extern template wostream& wostream::_M_insert(unsigned long long);
#endif
extern template wostream& wostream::_M_insert(double);
extern template wostream& wostream::_M_insert(long double);
extern template wostream& wostream::_M_insert(const void*);
#endif
#endif
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif
#endif /* _GLIBCXX_OSTREAM */
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @name Standard Stream Objects
*
* The <iostream> header declares the eight <em>standard stream
* objects</em>. For other declarations, see
* http://gcc.gnu.org/onlinedocs/libstdc++/manual/io.html
* and the @link iosfwd I/O forward declarations @endlink
*
* They are required by default to cooperate with the global C
* library's @c FILE streams, and to be available during program
* startup and termination. For more information, see the section of the
* manual linked to above.
*/
//@{
extern istream cin; /// Linked to standard input
extern ostream cout; /// Linked to standard output
extern ostream cerr; /// Linked to standard error (unbuffered)
extern ostream clog; /// Linked to standard error (buffered)
#ifdef _GLIBCXX_USE_WCHAR_T
extern wistream wcin; /// Linked to standard input
extern wostream wcout; /// Linked to standard output
extern wostream wcerr; /// Linked to standard error (unbuffered)
extern wostream wclog; /// Linked to standard error (buffered)
#endif
//@}
// For construction of filebuffers for cout, cin, cerr, clog et. al.
static ios_base::Init __ioinit;
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
#endif /* _GLIBCXX_IOSTREAM */
的确也不短,可是万能包含了多少这样的文件我们知道吗?所以,给句忠告:远离他。
看完了?本事不小嘛!!!!开眼界了吧?
标签:boolean ret port mmu term protect util nts quick
原文地址:https://www.cnblogs.com/caiyuchen/p/stdcpp.html