1// Input streams -*- C++ -*-
3// Copyright (C) 1997-2024 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
196#pragma GCC diagnostic push
197#pragma GCC diagnostic ignored "-Wlong-long"
199 operator>>(long long& __n)
200 { return _M_extract(__n); }
203 operator>>(unsigned long long& __n)
204 { return _M_extract(__n); }
205#pragma GCC diagnostic pop
211 * @brief Floating point arithmetic extractors
212 * @param __f A variable of builtin floating point type.
213 * @return @c *this if successful
215 * These functions use the stream's current locale (specifically, the
216 * @c num_get facet) to parse the input data.
219 operator>>(float& __f)
220 { return _M_extract(__f); }
223 operator>>(double& __f)
224 { return _M_extract(__f); }
227 operator>>(long double& __f)
228 { return _M_extract(__f); }
231#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
232 __attribute__((__always_inline__))
234 operator>>(_Float16& __f)
237 __istream_type& __ret = _M_extract(__flt);
238 ios_base::iostate __err = ios_base::goodbit;
239 if (__flt < -__FLT16_MAX__)
241 __f = -__FLT16_MAX__;
242 __err = ios_base::failbit;
244 else if (__flt > __FLT16_MAX__)
247 __err = ios_base::failbit;
250 __f = static_cast<_Float16>(__flt);
252 this->setstate(__err);
257#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
258 __attribute__((__always_inline__))
260 operator>>(_Float32& __f)
263 __istream_type& __ret = _M_extract(__flt);
264 __f = static_cast<_Float32> (__flt);
269#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
270 __attribute__((__always_inline__))
272 operator>>(_Float64& __f)
275 __istream_type& __ret = _M_extract(__dbl);
276 __f = static_cast<_Float64> (__dbl);
281#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
282 __attribute__((__always_inline__))
284 operator>>(_Float128& __f)
287 __istream_type& __ret = _M_extract(__ldbl);
288 __f = static_cast<_Float128> (__ldbl);
293#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
294 __attribute__((__always_inline__))
296 operator>>(__gnu_cxx::__bfloat16_t & __f)
299 __istream_type& __ret = _M_extract(__flt);
300 ios_base::iostate __err = ios_base::goodbit;
301 if (__flt < -__BFLT16_MAX__)
303 __f = -__BFLT16_MAX__;
304 __err = ios_base::failbit;
306 else if (__flt > __BFLT16_MAX__)
308 __f = __BFLT16_MAX__;
309 __err = ios_base::failbit;
312 __f = static_cast<__gnu_cxx::__bfloat16_t>(__flt);
314 this->setstate(__err);
320 * @brief Basic arithmetic extractors
321 * @param __p A variable of pointer type.
322 * @return @c *this if successful
324 * These functions use the stream's current locale (specifically, the
325 * @c num_get facet) to parse the input data.
328 operator>>(void*& __p)
329 { return _M_extract(__p); }
332 * @brief Extracting into another streambuf.
333 * @param __sb A pointer to a streambuf
335 * This function behaves like one of the basic arithmetic extractors,
336 * in that it also constructs a sentry object and has the same error
339 * If @p __sb is NULL, the stream will set failbit in its error state.
341 * Characters are extracted from this stream and inserted into the
342 * @p __sb streambuf until one of the following occurs:
344 * - the input stream reaches end-of-file,
345 * - insertion into the output buffer fails (in this case, the
346 * character that would have been inserted is not extracted), or
347 * - an exception occurs (and in this case is caught)
349 * If the function inserts no characters, failbit is set.
352 operator>>(__streambuf_type* __sb);
355 // [27.6.1.3] unformatted input
357 * @brief Character counting
358 * @return The number of characters extracted by the previous
359 * unformatted input function dispatched for this stream.
363 { return _M_gcount; }
367 * @name Unformatted Input Functions
369 * All the unformatted input functions have some common behavior.
370 * Each starts by constructing a temporary object of type
371 * std::basic_istream::sentry with the second argument (noskipws)
372 * set to true. This has several effects, concluding with the
373 * setting of a status flag; see the sentry documentation for more.
375 * If the sentry status is good, the function tries to extract
376 * whatever data is appropriate for the type of the argument.
378 * The number of characters extracted is stored for later retrieval
381 * If an exception is thrown during extraction, ios_base::badbit
382 * will be turned on in the stream's error state (without causing an
383 * ios_base::failure to be thrown) and the original exception will
384 * be rethrown if badbit is set in the exceptions mask.
388 * @brief Simple extraction.
389 * @return A character, or eof().
391 * Tries to extract a character. If none are available, sets failbit
392 * and returns traits::eof().
398 * @brief Simple extraction.
399 * @param __c The character in which to store data.
402 * Tries to extract a character and store it in @a __c. If none are
403 * available, sets failbit and returns traits::eof().
405 * @note This function is not overloaded on signed char and
412 * @brief Simple multiple-character extraction.
413 * @param __s Pointer to an array.
414 * @param __n Maximum number of characters to store in @a __s.
415 * @param __delim A "stop" character.
418 * Characters are extracted and stored into @a __s until one of the
421 * - @c __n-1 characters are stored
422 * - the input sequence reaches EOF
423 * - the next character equals @a __delim, in which case the character
426 * If no characters are stored, failbit is set in the stream's error
429 * In any case, a null character is stored into the next location in
432 * @note This function is not overloaded on signed char and
436 get(char_type* __s, streamsize __n, char_type __delim);
439 * @brief Simple multiple-character extraction.
440 * @param __s Pointer to an array.
441 * @param __n Maximum number of characters to store in @a s.
444 * Returns @c get(__s,__n,widen('\\n')).
447 get(char_type* __s, streamsize __n)
448 { return this->get(__s, __n, this->widen('\n')); }
451 * @brief Extraction into another streambuf.
452 * @param __sb A streambuf in which to store data.
453 * @param __delim A "stop" character.
456 * Characters are extracted and inserted into @a __sb until one of the
459 * - the input sequence reaches EOF
460 * - insertion into the output buffer fails (in this case, the
461 * character that would have been inserted is not extracted)
462 * - the next character equals @a __delim (in this case, the character
464 * - an exception occurs (and in this case is caught)
466 * If no characters are stored, failbit is set in the stream's error
470 get(__streambuf_type& __sb, char_type __delim);
473 * @brief Extraction into another streambuf.
474 * @param __sb A streambuf in which to store data.
477 * Returns @c get(__sb,widen('\\n')).
480 get(__streambuf_type& __sb)
481 { return this->get(__sb, this->widen('\n')); }
484 * @brief String extraction.
485 * @param __s A character array in which to store the data.
486 * @param __n Maximum number of characters to extract.
487 * @param __delim A "stop" character.
490 * Extracts and stores characters into @a __s until one of the
491 * following happens. Note that these criteria are required to be
492 * tested in the order listed here, to allow an input line to exactly
493 * fill the @a __s array without setting failbit.
495 * -# the input sequence reaches end-of-file, in which case eofbit
496 * is set in the stream error state
497 * -# the next character equals @c __delim, in which case the character
498 * is extracted (and therefore counted in @c gcount()) but not stored
499 * -# @c __n-1 characters are stored, in which case failbit is set
500 * in the stream error state
502 * If no characters are extracted, failbit is set. (An empty line of
503 * input should therefore not cause failbit to be set.)
505 * In any case, a null character is stored in the next location in
509 getline(char_type* __s, streamsize __n, char_type __delim);
512 * @brief String extraction.
513 * @param __s A character array in which to store the data.
514 * @param __n Maximum number of characters to extract.
517 * Returns @c getline(__s,__n,widen('\\n')).
520 getline(char_type* __s, streamsize __n)
521 { return this->getline(__s, __n, this->widen('\n')); }
524 * @brief Discarding characters
525 * @param __n Number of characters to discard.
526 * @param __delim A "stop" character.
529 * Extracts characters and throws them away until one of the
531 * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n
532 * characters are extracted
533 * - the input sequence reaches end-of-file
534 * - the next character equals @a __delim (in this case, the character
535 * is extracted); note that this condition will never occur if
536 * @a __delim equals @c traits::eof().
538 * NB: Provide three overloads, instead of the single function
539 * (with defaults) mandated by the Standard: this leads to a
540 * better performing implementation, while still conforming to
544 ignore(streamsize __n, int_type __delim);
547 ignore(streamsize __n);
553 * @brief Looking ahead in the stream
554 * @return The next character, or eof().
556 * If, after constructing the sentry object, @c good() is false,
557 * returns @c traits::eof(). Otherwise reads but does not extract
558 * the next input character.
564 * @brief Extraction without delimiters.
565 * @param __s A character array.
566 * @param __n Maximum number of characters to store.
569 * If the stream state is @c good(), extracts characters and stores
570 * them into @a __s until one of the following happens:
571 * - @a __n characters are stored
572 * - the input sequence reaches end-of-file, in which case the error
573 * state is set to @c failbit|eofbit.
575 * @note This function is not overloaded on signed char and
579 read(char_type* __s, streamsize __n);
582 * @brief Extraction until the buffer is exhausted, but no more.
583 * @param __s A character array.
584 * @param __n Maximum number of characters to store.
585 * @return The number of characters extracted.
587 * Extracts characters and stores them into @a __s depending on the
588 * number of characters remaining in the streambuf's buffer,
589 * @c rdbuf()->in_avail(), called @c A here:
590 * - if @c A @c == @c -1, sets eofbit and extracts no characters
591 * - if @c A @c == @c 0, extracts no characters
592 * - if @c A @c > @c 0, extracts @c min(A,n)
594 * The goal is to empty the current buffer, and to not request any
595 * more from the external input sequence controlled by the streambuf.
598 readsome(char_type* __s, streamsize __n);
601 * @brief Unextracting a single character.
602 * @param __c The character to push back into the input stream.
605 * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
607 * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
610 * @note This function first clears eofbit. Since no characters
611 * are extracted, the next call to @c gcount() will return 0,
612 * as required by DR 60.
615 putback(char_type __c);
618 * @brief Unextracting the previous character.
621 * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
623 * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
626 * @note This function first clears eofbit. Since no characters
627 * are extracted, the next call to @c gcount() will return 0,
628 * as required by DR 60.
634 * @brief Synchronizing the stream buffer.
635 * @return 0 on success, -1 on failure
637 * If @c rdbuf() is a null pointer, returns -1.
639 * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
640 * sets badbit and returns -1.
642 * Otherwise, returns 0.
644 * @note This function does not count the number of characters
645 * extracted, if any, and therefore does not affect the next
646 * call to @c gcount().
652 * @brief Getting the current read position.
653 * @return A file position object.
655 * If @c fail() is not false, returns @c pos_type(-1) to indicate
656 * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
658 * @note This function does not count the number of characters
659 * extracted, if any, and therefore does not affect the next
660 * call to @c gcount(). At variance with putback, unget and
661 * seekg, eofbit is not cleared first.
667 * @brief Changing the current read position.
668 * @param __pos A file position object.
671 * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If
672 * that function fails, sets failbit.
674 * @note This function first clears eofbit. It does not count the
675 * number of characters extracted, if any, and therefore does
676 * not affect the next call to @c gcount().
682 * @brief Changing the current read position.
683 * @param __off A file offset object.
684 * @param __dir The direction in which to seek.
687 * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir).
688 * If that function fails, sets failbit.
690 * @note This function first clears eofbit. It does not count the
691 * number of characters extracted, if any, and therefore does
692 * not affect the next call to @c gcount().
695 seekg(off_type, ios_base::seekdir);
700 : _M_gcount(streamsize(0))
703#if __cplusplus >= 201103L
704 basic_istream(const basic_istream&) = delete;
706 basic_istream(basic_istream&& __rhs)
707 : __ios_type(), _M_gcount(__rhs._M_gcount)
709 __ios_type::move(__rhs);
713 // 27.7.3.3 Assign/swap
715 basic_istream& operator=(const basic_istream&) = delete;
718 operator=(basic_istream&& __rhs)
725 swap(basic_istream& __rhs)
727 __ios_type::swap(__rhs);
728 std::swap(_M_gcount, __rhs._M_gcount);
732 template<typename _ValueT>
734 _M_extract(_ValueT& __v);
737 /// Explicit specialization declarations, defined in src/istream.cc.
740 basic_istream<char>::
741 getline(char_type* __s, streamsize __n, char_type __delim);
745 basic_istream<char>::
746 ignore(streamsize __n);
750 basic_istream<char>::
751 ignore(streamsize __n, int_type __delim);
753#ifdef _GLIBCXX_USE_WCHAR_T
755 basic_istream<wchar_t>&
756 basic_istream<wchar_t>::
757 getline(char_type* __s, streamsize __n, char_type __delim);
760 basic_istream<wchar_t>&
761 basic_istream<wchar_t>::
762 ignore(streamsize __n);
765 basic_istream<wchar_t>&
766 basic_istream<wchar_t>::
767 ignore(streamsize __n, int_type __delim);
771 * @brief Performs setup work for input streams.
773 * Objects of this class are created before all of the standard
774 * extractors are run. It is responsible for <em>exception-safe
775 * prefix and suffix operations,</em> although only prefix actions
776 * are currently required by the standard.
778 template<typename _CharT, typename _Traits>
779 class basic_istream<_CharT, _Traits>::sentry
785 /// Easy access to dependent types.
786 typedef _Traits traits_type;
787 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
788 typedef basic_istream<_CharT, _Traits> __istream_type;
789 typedef typename __istream_type::__ctype_type __ctype_type;
790 typedef typename _Traits::int_type __int_type;
793 * @brief The constructor performs all the work.
794 * @param __is The input stream to guard.
795 * @param __noskipws Whether to consume whitespace or not.
797 * If the stream state is good (@a __is.good() is true), then the
798 * following actions are performed, otherwise the sentry state
799 * is false (<em>not okay</em>) and failbit is set in the
802 * The sentry's preparatory actions are:
804 * -# if the stream is tied to an output stream, @c is.tie()->flush()
805 * is called to synchronize the output sequence
806 * -# if @a __noskipws is false, and @c ios_base::skipws is set in
807 * @c is.flags(), the sentry extracts and discards whitespace
808 * characters from the stream. The currently imbued locale is
809 * used to determine whether each character is whitespace.
811 * If the stream state is still good, then the sentry state becomes
815 sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
818 * @brief Quick status checking.
819 * @return The sentry state.
821 * For ease of use, sentries may be converted to booleans. The
822 * return value is that of the sentry state (true == okay).
824#if __cplusplus >= 201103L
827 operator bool() const
833 * @brief Character extractors
834 * @param __in An input stream.
835 * @param __c A character reference.
838 * Behaves like one of the formatted arithmetic extractors described in
839 * std::basic_istream. After constructing a sentry object with good
840 * status, this function extracts a character (if one is available) and
841 * stores it in @a __c. Otherwise, sets failbit in the input stream.
843 template<typename _CharT, typename _Traits>
844 basic_istream<_CharT, _Traits>&
845 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
847 template<class _Traits>
848 inline basic_istream<char, _Traits>&
849 operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
850 { return (__in >> reinterpret_cast<char&>(__c)); }
852 template<class _Traits>
853 inline basic_istream<char, _Traits>&
854 operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
855 { return (__in >> reinterpret_cast<char&>(__c)); }
859 template<typename _CharT, typename _Traits>
861 __istream_extract(basic_istream<_CharT, _Traits>&, _CharT*, streamsize);
863 void __istream_extract(istream&, char*, streamsize);
867 * @brief Character string extractors
868 * @param __in An input stream.
869 * @param __s A character array (or a pointer to an array before C++20).
872 * Behaves like one of the formatted arithmetic extractors described in
873 * `std::basic_istream`. After constructing a sentry object with good
874 * status, this function extracts up to `n` characters and stores them
875 * into the array `__s`. `n` is defined as:
877 * - if `width()` is greater than zero, `n` is `min(width(), n)`
878 * - otherwise `n` is the number of elements of the array
879 * - (before C++20 the pointer is assumed to point to an array of
880 * the largest possible size for an array of `char_type`).
882 * Characters are extracted and stored until one of the following happens:
883 * - `n - 1` characters are stored
885 * - the next character is whitespace according to the current locale
887 * `width(0)` is then called for the input stream.
889 * If no characters are extracted, sets failbit.
892#if __cplusplus <= 201703L
893 template<typename _CharT, typename _Traits>
894 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
895 inline basic_istream<_CharT, _Traits>&
896 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
899 // Function inlining might make the buffer size known, allowing us to
901 size_t __n = __builtin_object_size(__s, 0);
902 if (__n < sizeof(_CharT))
904 // There is not even space for the required null terminator.
905 __glibcxx_assert(__n >= sizeof(_CharT));
906 // No point calling __istream_extract, but still need to reset width.
908 __in.setstate(ios_base::failbit);
910 else if (__n != (size_t)-1)
912 __n /= sizeof(_CharT);
913 streamsize __w = __in.width();
914 std::__istream_extract(__in, __s, __n);
915 if (__in.good() && (__w <= 0 || __n < (size_t)__w))
917 // Stopped extracting early to avoid overflowing the buffer,
918 // but might have stopped anyway (and set eofbit) if at EOF.
919 const typename _Traits::int_type __c = __in.rdbuf()->sgetc();
920 const bool __eof = _Traits::eq_int_type(__c, _Traits::eof());
921 if (__builtin_expect(__eof, true)) // Assume EOF, not overflow.
922 __in.setstate(ios_base::eofbit);
928 // Buffer size is unknown, have to assume it's huge.
929 streamsize __n = __gnu_cxx::__numeric_traits<streamsize>::__max;
930 __n /= sizeof(_CharT);
931 std::__istream_extract(__in, __s, __n);
936 template<class _Traits>
937 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
938 inline basic_istream<char, _Traits>&
939 operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
940 { return __in >> reinterpret_cast<char*>(__s); }
942 template<class _Traits>
943 __attribute__((__nonnull__(2), __access__(__write_only__, 2)))
944 inline basic_istream<char, _Traits>&
945 operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
946 { return __in >> reinterpret_cast<char*>(__s); }
948 // _GLIBCXX_RESOLVE_LIB_DEFECTS
949 // 2499. operator>>(istream&, char*) makes it hard to avoid buffer overflows
950 template<typename _CharT, typename _Traits, size_t _Num>
951 inline basic_istream<_CharT, _Traits>&
952 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT (&__s)[_Num])
954 static_assert(_Num <= __gnu_cxx::__numeric_traits<streamsize>::__max);
955 std::__istream_extract(__in, __s, _Num);
959 template<class _Traits, size_t _Num>
960 inline basic_istream<char, _Traits>&
961 operator>>(basic_istream<char, _Traits>& __in, unsigned char (&__s)[_Num])
962 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
964 template<class _Traits, size_t _Num>
965 inline basic_istream<char, _Traits>&
966 operator>>(basic_istream<char, _Traits>& __in, signed char (&__s)[_Num])
967 { return __in >> reinterpret_cast<char(&)[_Num]>(__s); }
972 * @brief Template class basic_iostream
975 * @tparam _CharT Type of character stream.
976 * @tparam _Traits Traits for character type, defaults to
977 * char_traits<_CharT>.
979 * This class multiply inherits from the input and output stream classes
980 * simply to provide a single interface.
982 template<typename _CharT, typename _Traits>
984 : public basic_istream<_CharT, _Traits>,
985 public basic_ostream<_CharT, _Traits>
988 // _GLIBCXX_RESOLVE_LIB_DEFECTS
989 // 271. basic_iostream missing typedefs
990 // Types (inherited):
991 typedef _CharT char_type;
992 typedef typename _Traits::int_type int_type;
993 typedef typename _Traits::pos_type pos_type;
994 typedef typename _Traits::off_type off_type;
995 typedef _Traits traits_type;
997 // Non-standard Types:
998 typedef basic_istream<_CharT, _Traits> __istream_type;
999 typedef basic_ostream<_CharT, _Traits> __ostream_type;
1002 * @brief Constructor does nothing.
1004 * Both of the parent classes are initialized with the same
1005 * streambuf pointer passed to this constructor.
1008 basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
1009 : __istream_type(__sb), __ostream_type(__sb) { }
1012 * @brief Destructor does nothing.
1015 ~basic_iostream() { }
1019 : __istream_type(), __ostream_type() { }
1021#if __cplusplus >= 201103L
1022 basic_iostream(const basic_iostream&) = delete;
1024 basic_iostream(basic_iostream&& __rhs)
1025 : __istream_type(std::move(__rhs)), __ostream_type(*this)
1028 // 27.7.3.3 Assign/swap
1030 basic_iostream& operator=(const basic_iostream&) = delete;
1033 operator=(basic_iostream&& __rhs)
1040 swap(basic_iostream& __rhs)
1041 { __istream_type::swap(__rhs); }
1046 * @brief Quick and easy way to eat whitespace
1048 * This manipulator extracts whitespace characters, stopping when the
1049 * next character is non-whitespace, or when the input sequence is empty.
1050 * If the sequence is empty, @c eofbit is set in the stream, but not
1053 * The current locale is used to distinguish whitespace characters.
1059 * std::cin >> std::ws >> mc;
1061 * will skip leading whitespace before calling operator>> on cin and your
1062 * object. Note that the same effect can be achieved by creating a
1063 * std::basic_istream::sentry inside your definition of operator>>.
1065 template<typename _CharT, typename _Traits>
1066 basic_istream<_CharT, _Traits>&
1067 ws(basic_istream<_CharT, _Traits>& __is);
1069#if __cplusplus >= 201103L
1070 // C++11 27.7.2.6 Rvalue stream extraction [istream.rvalue]
1071 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1072 // 2328. Rvalue stream extraction should use perfect forwarding
1073 // 1203. More useful rvalue stream insertion
1075#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
1076 template<typename _Is, typename _Tp>
1077 requires __derived_from_ios_base<_Is>
1078 && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); }
1079 using __rvalue_stream_extraction_t = _Is&&;
1081 template<typename _Is, typename _Tp,
1082 typename = _Require_derived_from_ios_base<_Is>,
1083 typename = decltype(std::declval<_Is&>() >> std::declval<_Tp>())>
1084 using __rvalue_stream_extraction_t = _Is&&;
1088 * @brief Generic extractor for rvalue stream
1089 * @param __is An input stream.
1090 * @param __x A reference to the extraction target.
1093 * This is just a forwarding function to allow extraction from
1094 * rvalue streams since they won't bind to the extractor functions
1095 * that take an lvalue reference.
1097 template<typename _Istream, typename _Tp>
1098 inline __rvalue_stream_extraction_t<_Istream, _Tp>
1099 operator>>(_Istream&& __is, _Tp&& __x)
1101 __is >> std::forward<_Tp>(__x);
1102 return std::move(__is);
1106_GLIBCXX_END_NAMESPACE_VERSION
1109#include <bits/istream.tcc>
1111#endif /* _GLIBCXX_ISTREAM */