1// Input streams -*- C++ -*-
3// Copyright (C) 1997-2023 Free Software Foundation, Inc.
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
26// ISO C++ 14882: 27.6.1 Input streams
29/** @file include/istream
30 * This is a Standard C++ Library header.
33#ifndef _GLIBCXX_ISTREAM
34#define _GLIBCXX_ISTREAM 1
36#pragma GCC system_header
38#include <bits/requires_hosted.h> // iostreams
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
48 * @brief Template class basic_istream.
51 * @tparam _CharT Type of character stream.
52 * @tparam _Traits Traits for character type, defaults to
53 * char_traits<_CharT>.
55 * This is the base class for all input streams. It provides text
56 * formatting of all builtin types, and communicates with any class
57 * derived from basic_streambuf to do the actual input.
59 template<typename _CharT, typename _Traits>
60 class basic_istream : virtual public basic_ios<_CharT, _Traits>
63 // Types (inherited from basic_ios (27.4.4)):
64 typedef _CharT char_type;
65 typedef typename _Traits::int_type int_type;
66 typedef typename _Traits::pos_type pos_type;
67 typedef typename _Traits::off_type off_type;
68 typedef _Traits traits_type;
70 // Non-standard Types:
71 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
72 typedef basic_ios<_CharT, _Traits> __ios_type;
73 typedef basic_istream<_CharT, _Traits> __istream_type;
74 typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
76 typedef ctype<_CharT> __ctype_type;
81 * The number of characters extracted in the previous unformatted
82 * function; see gcount().
88 * @brief Base constructor.
90 * This ctor is almost never called by the user directly, rather from
91 * derived classes' initialization lists, which pass a pointer to
92 * their own stream buffer.
95 basic_istream(__streambuf_type* __sb)
96 : _M_gcount(streamsize(0))
100 * @brief Base destructor.
102 * This does very little apart from providing a virtual base dtor.
106 { _M_gcount = streamsize(0); }
108 /// Safe prefix/suffix operations.
114 * @brief Interface for manipulators.
116 * Manipulators such as @c std::ws and @c std::dec use these
117 * functions in constructs like
118 * <code>std::cin >> std::ws</code>.
119 * For more information, see the iomanip header.
122 operator>>(__istream_type& (*__pf)(__istream_type&))
123 { return __pf(*this); }
126 operator>>(__ios_type& (*__pf)(__ios_type&))
133 operator>>(ios_base& (*__pf)(ios_base&))
144 * All the @c operator>> functions (aka <em>formatted input
145 * functions</em>) have some common behavior. Each starts by
146 * constructing a temporary object of type std::basic_istream::sentry
147 * with the second argument (noskipws) set to false. This has several
148 * effects, concluding with the setting of a status flag; see the
149 * sentry documentation for more.
151 * If the sentry status is good, the function tries to extract
152 * whatever data is appropriate for the type of the argument.
154 * If an exception is thrown during extraction, ios_base::badbit
155 * will be turned on in the stream's error state (without causing an
156 * ios_base::failure to be thrown) and the original exception will
157 * be rethrown if badbit is set in the exceptions mask.
162 * @brief Integer arithmetic extractors
163 * @param __n A variable of builtin integral type.
164 * @return @c *this if successful
166 * These functions use the stream's current locale (specifically, the
167 * @c num_get facet) to parse the input data.
170 operator>>(bool& __n)
171 { return _M_extract(__n); }
174 operator>>(short& __n);
177 operator>>(unsigned short& __n)
178 { return _M_extract(__n); }
181 operator>>(int& __n);
184 operator>>(unsigned int& __n)
185 { return _M_extract(__n); }
188 operator>>(long& __n)
189 { return _M_extract(__n); }
192 operator>>(unsigned long& __n)
193 { return _M_extract(__n); }
195#ifdef _GLIBCXX_USE_LONG_LONG
197 operator>>(long long& __n)
198 { return _M_extract(__n); }
201 operator>>(unsigned long long& __n)
202 { return _M_extract(__n); }
208 * @brief Floating point arithmetic extractors
209 * @param __f A variable of builtin floating point type.
210 * @return @c *this if successful
212 * These functions use the stream's current locale (specifically, the
213 * @c num_get facet) to parse the input data.
216 operator>>(float& __f)
217 { return _M_extract(__f); }
220 operator>>(double& __f)
221 { return _M_extract(__f); }
224 operator>>(long double& __f)
225 { return _M_extract(__f); }
228#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
229 __attribute__((__always_inline__))
231 operator>>(_Float16& __f)
234 __istream_type& __ret = _M_extract(__flt);
235 ios_base::iostate __err = ios_base::goodbit;
236 if (__flt < -__FLT16_MAX__)
238 __f = -__FLT16_MAX__;
239 __err = ios_base::failbit;
241 else if (__flt > __FLT16_MAX__)
244 __err = ios_base::failbit;
247 __f = static_cast<_Float16>(__flt);
249 this->setstate(__err);
254#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
255 __attribute__((__always_inline__))
257 operator>>(_Float32& __f)
260 __istream_type& __ret = _M_extract(__flt);
261 __f = static_cast<_Float32> (__flt);
266#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
267 __attribute__((__always_inline__))
269 operator>>(_Float64& __f)
272 __istream_type& __ret = _M_extract(__dbl);
273 __f = static_cast<_Float64> (__dbl);
278#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
279 __attribute__((__always_inline__))
281 operator>>(_Float128& __f)
284 __istream_type& __ret = _M_extract(__ldbl);
285 __f = static_cast<_Float128> (__ldbl);
290#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
291 __attribute__((__always_inline__))
293 operator>>(__gnu_cxx::__bfloat16_t & __f)
296 __istream_type& __ret = _M_extract(__flt);
297 ios_base::iostate __err = ios_base::goodbit;
298 if (__flt < -__BFLT16_MAX__)
300 __f = -__BFLT16_MAX__;
301 __err = ios_base::failbit;
303 else if (__flt > __BFLT16_MAX__)
305 __f = __BFLT16_MAX__;
306 __err = ios_base::failbit;
309 __f = static_cast<__gnu_cxx::__bfloat16_t>(__flt);
311 this->setstate(__err);
317 * @brief Basic arithmetic extractors
318 * @param __p A variable of pointer type.
319 * @return @c *this if successful
321 * These functions use the stream's current locale (specifically, the
322 * @c num_get facet) to parse the input data.
325 operator>>(void*& __p)
326 { return _M_extract(__p); }
329 * @brief Extracting into another streambuf.
330 * @param __sb A pointer to a streambuf
332 * This function behaves like one of the basic arithmetic extractors,
333 * in that it also constructs a sentry object and has the same error
336 * If @p __sb is NULL, the stream will set failbit in its error state.
338 * Characters are extracted from this stream and inserted into the
339 * @p __sb streambuf until one of the following occurs:
341 * - the input stream reaches end-of-file,
342 * - insertion into the output buffer fails (in this case, the
343 * character that would have been inserted is not extracted), or
344 * - an exception occurs (and in this case is caught)
346 * If the function inserts no characters, failbit is set.
349 operator>>(__streambuf_type* __sb);
352 // [27.6.1.3] unformatted input
354 * @brief Character counting
355 * @return The number of characters extracted by the previous
356 * unformatted input function dispatched for this stream.
360 { return _M_gcount; }
364 * @name Unformatted Input Functions
366 * All the unformatted input functions have some common behavior.
367 * Each starts by constructing a temporary object of type
368 * std::basic_istream::sentry with the second argument (noskipws)
369 * set to true. This has several effects, concluding with the
370 * setting of a status flag; see the sentry documentation for more.
372 * If the sentry status is good, the function tries to extract
373 * whatever data is appropriate for the type of the argument.
375 * The number of characters extracted is stored for later retrieval
378 * If an exception is thrown during extraction, ios_base::badbit
379 * will be turned on in the stream's error state (without causing an
380 * ios_base::failure to be thrown) and the original exception will
381 * be rethrown if badbit is set in the exceptions mask.
385 * @brief Simple extraction.
386 * @return A character, or eof().
388 * Tries to extract a character. If none are available, sets failbit
389 * and returns traits::eof().
395 * @brief Simple extraction.
396 * @param __c The character in which to store data.
399 * Tries to extract a character and store it in @a __c. If none are
400 * available, sets failbit and returns traits::eof().
402 * @note This function is not overloaded on signed char and
409 * @brief Simple multiple-character extraction.
410 * @param __s Pointer to an array.
411 * @param __n Maximum number of characters to store in @a __s.
412 * @param __delim A "stop" character.
415 * Characters are extracted and stored into @a __s until one of the
418 * - @c __n-1 characters are stored
419 * - the input sequence reaches EOF
420 * - the next character equals @a __delim, in which case the character
423 * If no characters are stored, failbit is set in the stream's error
426 * In any case, a null character is stored into the next location in
429 * @note This function is not overloaded on signed char and
433 get(char_type* __s, streamsize __n, char_type __delim);
436 * @brief Simple multiple-character extraction.
437 * @param __s Pointer to an array.
438 * @param __n Maximum number of characters to store in @a s.
441 * Returns @c get(__s,__n,widen('\\n')).
444 get(char_type* __s, streamsize __n)
445 { return this->get(__s, __n, this->widen('\n')); }
448 * @brief Extraction into another streambuf.
449 * @param __sb A streambuf in which to store data.
450 * @param __delim A "stop" character.
453 * Characters are extracted and inserted into @a __sb until one of the
456 * - the input sequence reaches EOF
457 * - insertion into the output buffer fails (in this case, the
458 * character that would have been inserted is not extracted)
459 * - the next character equals @a __delim (in this case, the character
461 * - an exception occurs (and in this case is caught)
463 * If no characters are stored, failbit is set in the stream's error
467 get(__streambuf_type& __sb, char_type __delim);
470 * @brief Extraction into another streambuf.
471 * @param __sb A streambuf in which to store data.
474 * Returns @c get(__sb,widen('\\n')).
477 get(__streambuf_type& __sb)
478 { return this->get(__sb, this->widen('\n')); }
481 * @brief String extraction.
482 * @param __s A character array in which to store the data.
483 * @param __n Maximum number of characters to extract.
484 * @param __delim A "stop" character.
487 * Extracts and stores characters into @a __s until one of the
488 * following happens. Note that these criteria are required to be
489 * tested in the order listed here, to allow an input line to exactly
490 * fill the @a __s array without setting failbit.
492 * -# the input sequence reaches end-of-file, in which case eofbit
493 * is set in the stream error state
494 * -# the next character equals @c __delim, in which case the character
495 * is extracted (and therefore counted in @c gcount()) but not stored
496 * -# @c __n-1 characters are stored, in which case failbit is set
497 * in the stream error state
499 * If no characters are extracted, failbit is set. (An empty line of
500 * input should therefore not cause failbit to be set.)
502 * In any case, a null character is stored in the next location in
506 getline(char_type* __s, streamsize __n, char_type __delim);
509 * @brief String extraction.
510 * @param __s A character array in which to store the data.
511 * @param __n Maximum number of characters to extract.
514 * Returns @c getline(__s,__n,widen('\\n')).
517 getline(char_type* __s, streamsize __n)
518 { return this->getline(__s, __n, this->widen('\n')); }
521 * @brief Discarding characters
522 * @param __n Number of characters to discard.
523 * @param __delim A "stop" character.
526 * Extracts characters and throws them away until one of the
528 * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
529 * characters are extracted
530 * - the input sequence reaches end-of-file
531 * - the next character equals @a __delim (in this case, the character
532 * is extracted); note that this condition will never occur if
533 * @a __delim equals @c traits::eof().
535 * NB: Provide three overloads, instead of the single function
536 * (with defaults) mandated by the Standard: this leads to a
537 * better performing implementation, while still conforming to
541 ignore(streamsize __n, int_type __delim);
544 ignore(streamsize __n);
550 * @brief Looking ahead in the stream
551 * @return The next character, or eof().
553 * If, after constructing the sentry object, @c good() is false,
554 * returns @c traits::eof(). Otherwise reads but does not extract
555 * the next input character.
561 * @brief Extraction without delimiters.
562 * @param __s A character array.
563 * @param __n Maximum number of characters to store.
566 * If the stream state is @c good(), extracts characters and stores
567 * them into @a __s until one of the following happens:
568 * - @a __n characters are stored
569 * - the input sequence reaches end-of-file, in which case the error
570 * state is set to @c failbit|eofbit.
572 * @note This function is not overloaded on signed char and
576 read(char_type* __s, streamsize __n);
579 * @brief Extraction until the buffer is exhausted, but no more.
580 * @param __s A character array.
581 * @param __n Maximum number of characters to store.
582 * @return The number of characters extracted.
584 * Extracts characters and stores them into @a __s depending on the
585 * number of characters remaining in the streambuf's buffer,
586 * @c rdbuf()->in_avail(), called @c A here:
587 * - if @c A @c == @c -1, sets eofbit and extracts no characters
588 * - if @c A @c == @c 0, extracts no characters
589 * - if @c A @c > @c 0, extracts @c min(A,n)
591 * The goal is to empty the current buffer, and to not request any
592 * more from the external input sequence controlled by the streambuf.
595 readsome(char_type* __s, streamsize __n);
598 * @brief Unextracting a single character.
599 * @param __c The character to push back into the input stream.
602 * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
604 * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
607 * @note This function first clears eofbit. Since no characters
608 * are extracted, the next call to @c gcount() will return 0,
609 * as required by DR 60.
612 putback(char_type __c);
615 * @brief Unextracting the previous character.
618 * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
620 * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
623 * @note This function first clears eofbit. Since no characters
624 * are extracted, the next call to @c gcount() will return 0,
625 * as required by DR 60.
631 * @brief Synchronizing the stream buffer.
632 * @return 0 on success, -1 on failure
634 * If @c rdbuf() is a null pointer, returns -1.
636 * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
637 * sets badbit and returns -1.
639 * Otherwise, returns 0.
641 * @note This function does not count the number of characters
642 * extracted, if any, and therefore does not affect the next
643 * call to @c gcount().
649 * @brief Getting the current read position.
650 * @return A file position object.
652 * If @c fail() is not false, returns @c pos_type(-1) to indicate
653 * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
655 * @note This function does not count the number of characters
656 * extracted, if any, and therefore does not affect the next
657 * call to @c gcount(). At variance with putback, unget and
658 * seekg, eofbit is not cleared first.
664 * @brief Changing the current read position.
665 * @param __pos A file position object.
668 * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If
669 * that function fails, sets failbit.
671 * @note This function first clears eofbit. It does not count the
672 * number of characters extracted, if any, and therefore does
673 * not affect the next call to @c gcount().
679 * @brief Changing the current read position.
680 * @param __off A file offset object.
681 * @param __dir The direction in which to seek.
684 * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
685 * If that function fails, sets failbit.
687 * @note This function first clears eofbit. It does not count the
688 * number of characters extracted, if any, and therefore does
689 * not affect the next call to @c gcount().
692 seekg(off_type, ios_base::seekdir);
697 : _M_gcount(streamsize(0))
700#if __cplusplus >= 201103L
701 basic_istream(const basic_istream&) = delete;
703 basic_istream(basic_istream&& __rhs)
704 : __ios_type(), _M_gcount(__rhs._M_gcount)
706 __ios_type::move(__rhs);
710 // 27.7.3.3 Assign/swap
712 basic_istream& operator=(const basic_istream&) = delete;
715 operator=(basic_istream&& __rhs)
722 swap(basic_istream& __rhs)
724 __ios_type::swap(__rhs);
725 std::swap(_M_gcount, __rhs._M_gcount);
729 template<typename _ValueT>
731 _M_extract(_ValueT& __v);
734 /// Explicit specialization declarations, defined in src/istream.cc.
737 basic_istream<char>::
738 getline(char_type* __s, streamsize __n, char_type __delim);
742 basic_istream<char>::
743 ignore(streamsize __n);
747 basic_istream<char>::
748 ignore(streamsize __n, int_type __delim);
750#ifdef _GLIBCXX_USE_WCHAR_T
752 basic_istream<wchar_t>&
753 basic_istream<wchar_t>::
754 getline(char_type* __s, streamsize __n, char_type __delim);
757 basic_istream<wchar_t>&
758 basic_istream<wchar_t>::
759 ignore(streamsize __n);
762 basic_istream<wchar_t>&
763 basic_istream<wchar_t>::
764 ignore(streamsize __n, int_type __delim);
768 * @brief Performs setup work for input streams.
770 * Objects of this class are created before all of the standard
771 * extractors are run. It is responsible for <em>exception-safe
772 * prefix and suffix operations,</em> although only prefix actions
773 * are currently required by the standard.
775 template<typename _CharT, typename _Traits>
776 class basic_istream<_CharT, _Traits>::sentry
782 /// Easy access to dependent types.
783 typedef _Traits traits_type;
784 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
785 typedef basic_istream<_CharT, _Traits> __istream_type;
786 typedef typename __istream_type::__ctype_type __ctype_type;
787 typedef typename _Traits::int_type __int_type;
790 * @brief The constructor performs all the work.
791 * @param __is The input stream to guard.
792 * @param __noskipws Whether to consume whitespace or not.
794 * If the stream state is good (@a __is.good() is true), then the
795 * following actions are performed, otherwise the sentry state
796 * is false (<em>not okay</em>) and failbit is set in the
799 * The sentry's preparatory actions are:
801 * -# if the stream is tied to an output stream, @c is.tie()->flush()
802 * is called to synchronize the output sequence
803 * -# if @a __noskipws is false, and @c ios_base::skipws is set in
804 * @c is.flags(), the sentry extracts and discards whitespace
805 * characters from the stream. The currently imbued locale is
806 * used to determine whether each character is whitespace.
808 * If the stream state is still good, then the sentry state becomes
812 sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
815 * @brief Quick status checking.
816 * @return The sentry state.
818 * For ease of use, sentries may be converted to booleans. The
819 * return value is that of the sentry state (true == okay).
821#if __cplusplus >= 201103L
824 operator bool() const
830 * @brief Character extractors
831 * @param __in An input stream.
832 * @param __c A character reference.
835 * Behaves like one of the formatted arithmetic extractors described in
836 * std::basic_istream. After constructing a sentry object with good
837 * status, this function extracts a character (if one is available) and
838 * stores it in @a __c. Otherwise, sets failbit in the input stream.
840 template<typename _CharT, typename _Traits>
841 basic_istream<_CharT, _Traits>&
842 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
844 template<class _Traits>
845 inline basic_istream<char, _Traits>&
846 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
847 { return (__in >> reinterpret_cast<char&>(__c)); }
849 template<class _Traits>
850 inline basic_istream<char, _Traits>&
851 operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
852 { return (__in >> reinterpret_cast<char&>(__c)); }
856 template<typename _CharT, typename _Traits>
858 __istream_extract(basic_istream<_CharT, _Traits>&, _CharT*, streamsize);
860 void __istream_extract(istream&, char*, streamsize);
864 * @brief Character string extractors
865 * @param __in An input stream.
866 * @param __s A character array (or a pointer to an array before C++20).
869 * Behaves like one of the formatted arithmetic extractors described in
870 * `std::basic_istream`. After constructing a sentry object with good
871 * status, this function extracts up to `n` characters and stores them
872 * into the array `__s`. `n` is defined as:
874 * - if `width()` is greater than zero, `n` is `min(width(), n)`
875 * - otherwise `n` is the number of elements of the array
876 * - (before C++20 the pointer is assumed to point to an array of
877 * the largest possible size for an array of `char_type`).
879 * Characters are extracted and stored until one of the following happens:
880 * - `n - 1` characters are stored
882 * - the next character is whitespace according to the current locale
884 * `width(0)` is then called for the input stream.
886 * If no characters are extracted, sets failbit.
889#if __cplusplus <= 201703L
890 template<typename _CharT, typename _Traits>
891 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
892 inline basic_istream<_CharT, _Traits>&
893 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
896 // Function inlining might make the buffer size known, allowing us to
898 size_t __n = __builtin_object_size(__s, 0);
899 if (__n < sizeof(_CharT))
901 // There is not even space for the required null terminator.
902 __glibcxx_assert(__n >= sizeof(_CharT));
903 // No point calling __istream_extract, but still need to reset width.
905 __in.setstate(ios_base::failbit);
907 else if (__n != (size_t)-1)
909 __n /= sizeof(_CharT);
910 streamsize __w = __in.width();
911 std::__istream_extract(__in, __s, __n);
912 if (__in.good() && (__w <= 0 || __n < __w))
914 // Stopped extracting early to avoid overflowing the buffer,
915 // but might have stopped anyway (and set eofbit) if at EOF.
916 const typename _Traits::int_type __c = __in.rdbuf()->sgetc();
917 const bool __eof = _Traits::eq_int_type(__c, _Traits::eof());
918 if (__builtin_expect(__eof, true)) // Assume EOF, not overflow.
919 __in.setstate(ios_base::eofbit);
925 // Buffer size is unknown, have to assume it's huge.
926 streamsize __n = __gnu_cxx::__numeric_traits<streamsize>::__max;
927 __n /= sizeof(_CharT);
928 std::__istream_extract(__in, __s, __n);
933 template<class _Traits>
934 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
935 inline basic_istream<char, _Traits>&
936 operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
937 { return __in >> reinterpret_cast<char*>(__s); }
939 template<class _Traits>
940 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
941 inline basic_istream<char, _Traits>&
942 operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
943 { return __in >> reinterpret_cast<char*>(__s); }
945 // _GLIBCXX_RESOLVE_LIB_DEFECTS
946 // 2499. operator>>(istream&, char*) makes it hard to avoid buffer overflows
947 template<typename _CharT, typename _Traits, size_t _Num>
948 inline basic_istream<_CharT, _Traits>&
949 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT (&__s)[_Num])
951 static_assert(_Num <= __gnu_cxx::__numeric_traits<streamsize>::__max);
952 std::__istream_extract(__in, __s, _Num);
956 template<class _Traits, size_t _Num>
957 inline basic_istream<char, _Traits>&
958 operator>>(basic_istream<char, _Traits>& __in, unsigned char (&__s)[_Num])
959 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
961 template<class _Traits, size_t _Num>
962 inline basic_istream<char, _Traits>&
963 operator>>(basic_istream<char, _Traits>& __in, signed char (&__s)[_Num])
964 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
969 * @brief Template class basic_iostream
972 * @tparam _CharT Type of character stream.
973 * @tparam _Traits Traits for character type, defaults to
974 * char_traits<_CharT>.
976 * This class multiply inherits from the input and output stream classes
977 * simply to provide a single interface.
979 template<typename _CharT, typename _Traits>
981 : public basic_istream<_CharT, _Traits>,
982 public basic_ostream<_CharT, _Traits>
985 // _GLIBCXX_RESOLVE_LIB_DEFECTS
986 // 271. basic_iostream missing typedefs
987 // Types (inherited):
988 typedef _CharT char_type;
989 typedef typename _Traits::int_type int_type;
990 typedef typename _Traits::pos_type pos_type;
991 typedef typename _Traits::off_type off_type;
992 typedef _Traits traits_type;
994 // Non-standard Types:
995 typedef basic_istream<_CharT, _Traits> __istream_type;
996 typedef basic_ostream<_CharT, _Traits> __ostream_type;
999 * @brief Constructor does nothing.
1001 * Both of the parent classes are initialized with the same
1002 * streambuf pointer passed to this constructor.
1005 basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
1006 : __istream_type(__sb), __ostream_type(__sb) { }
1009 * @brief Destructor does nothing.
1012 ~basic_iostream() { }
1016 : __istream_type(), __ostream_type() { }
1018#if __cplusplus >= 201103L
1019 basic_iostream(const basic_iostream&) = delete;
1021 basic_iostream(basic_iostream&& __rhs)
1022 : __istream_type(std::move(__rhs)), __ostream_type(*this)
1025 // 27.7.3.3 Assign/swap
1027 basic_iostream& operator=(const basic_iostream&) = delete;
1030 operator=(basic_iostream&& __rhs)
1037 swap(basic_iostream& __rhs)
1038 { __istream_type::swap(__rhs); }
1043 * @brief Quick and easy way to eat whitespace
1045 * This manipulator extracts whitespace characters, stopping when the
1046 * next character is non-whitespace, or when the input sequence is empty.
1047 * If the sequence is empty, @c eofbit is set in the stream, but not
1050 * The current locale is used to distinguish whitespace characters.
1056 * std::cin >> std::ws >> mc;
1058 * will skip leading whitespace before calling operator>> on cin and your
1059 * object. Note that the same effect can be achieved by creating a
1060 * std::basic_istream::sentry inside your definition of operator>>.
1062 template<typename _CharT, typename _Traits>
1063 basic_istream<_CharT, _Traits>&
1064 ws(basic_istream<_CharT, _Traits>& __is);
1066#if __cplusplus >= 201103L
1067 // C++11 27.7.2.6 Rvalue stream extraction [istream.rvalue]
1068 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1069 // 2328. Rvalue stream extraction should use perfect forwarding
1070 // 1203. More useful rvalue stream insertion
1072#if __cpp_lib_concepts
1073 template<typename _Is, typename _Tp>
1074 requires __derived_from_ios_base<_Is>
1075 && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); }
1076 using __rvalue_stream_extraction_t = _Is&&;
1078 template<typename _Is, typename _Tp,
1079 typename = _Require_derived_from_ios_base<_Is>,
1080 typename = decltype(std::declval<_Is&>() >> std::declval<_Tp>())>
1081 using __rvalue_stream_extraction_t = _Is&&;
1085 * @brief Generic extractor for rvalue stream
1086 * @param __is An input stream.
1087 * @param __x A reference to the extraction target.
1090 * This is just a forwarding function to allow extraction from
1091 * rvalue streams since they won't bind to the extractor functions
1092 * that take an lvalue reference.
1094 template<typename _Istream, typename _Tp>
1095 inline __rvalue_stream_extraction_t<_Istream, _Tp>
1096 operator>>(_Istream&& __is, _Tp&& __x)
1098 __is >> std::forward<_Tp>(__x);
1099 return std::move(__is);
1103_GLIBCXX_END_NAMESPACE_VERSION
1106#include <bits/istream.tcc>
1108#endif /* _GLIBCXX_ISTREAM */