std::basic_ispanstream(3)
π¦ NAME π¦
std::basic_ispanstream(3) is the manual page name, straight outta the C++ Standard Library, and the class itself is std::basic_ispanstream. It's giving fixed-buffer input stream realness, and we're about to go through every detail together. π
β¨ SYNOPSIS β¨
Defined in header <spanstream>:
template<
class CharT,
class Traits = std::char_traits<CharT> (since C++23)
> class basic_ispanstream
: public basic_istream<CharT, Traits>
The class template std::basic_ispanstream implements input operations on streams based on fixed buffers. No cap. β¨
At the low level, the class essentially wraps a raw device implementation of std::basic_spanbuf into a higher-level interface of std::basic_istream. The complete interface to unique std::basic_spanbuf members is provided. Periodt. π
There's an inheritance diagram named std-basic ispanstream-inheritance.svg β like, that's literally the label: Inheritance diagram. π
Several typedefs for common character types are provided:
Defined in header <spanstream>:
std::ispanstreamβstd::basic_ispanstream<char>std::wispanstreamβstd::basic_ispanstream<wchar_t>
πΈ Member types πΈ
char_typeβCharTtraits_typeβTraits; the program is ill-formed ifTraits::char_typeis notCharT. (important!!)int_typeβTraits::int_typepos_typeβTraits::pos_typeoff_typeβTraits::off_type
π Data members π
sb(private) β the wrappedstd::basic_spanbuf. It's an exposition-only member object*.
π Member functions π
- constructor (
C++23) β constructs thebasic_ispanstream(public member function) - destructor
[virtual](C++23) β destroys thebasic_ispanstream(virtual public member function) operator=(C++23) β move-assignments thebasic_ispanstream(public member function)swap(C++23) β swaps twobasic_ispanstreamobjects (public member function)rdbuf(C++23) β obtains the address of the wrapped raw span device object (public member function)
Underlying buffer operations
span(C++23) β gets or sets the underlying buffer of the wrapped span device object (public member function)
π₯ Non-member functions π₯
std::swap(std::basic_ispanstream)(C++23) β specializes thestd::swapalgorithm (function template)
π Inherited from std::basic_istream π
Member functions
Formatted input
operator>>β extracts formatted data (public member function ofstd::basic_istream<CharT,Traits>)
Unformatted input
getβ extracts characters (public member function ofstd::basic_istream<CharT,Traits>)peekβ reads the next character without extracting it (public member function ofstd::basic_istream<CharT,Traits>)ungetβ unextracts a character (public member function ofstd::basic_istream<CharT,Traits>)putbackβ puts a character into input stream (public member function ofstd::basic_istream<CharT,Traits>)getlineβ extracts characters until the given character is found (public member function ofstd::basic_istream<CharT,Traits>)ignoreβ extracts and discards characters until the given character is found (public member function ofstd::basic_istream<CharT,Traits>)readβ extracts blocks of characters (public member function ofstd::basic_istream<CharT,Traits>)readsomeβ extracts already available blocks of characters (public member function ofstd::basic_istream<CharT,Traits>)gcountβ returns number of characters extracted by last unformatted input operation (public member function ofstd::basic_istream<CharT,Traits>)
Positioning
tellgβ returns the input position indicator (public member function ofstd::basic_istream<CharT,Traits>)seekgβ sets the input position indicator (public member function ofstd::basic_istream<CharT,Traits>)
Miscellaneous
syncβ synchronizes with the underlying storage device (public member function ofstd::basic_istream<CharT,Traits>)
Member classes
sentryβ implements basic logic for preparation of the stream for input operations (public member class ofstd::basic_istream<CharT,Traits>)
π Inherited from std::basic_ios π
Member types
char_typeβCharTtraits_typeβTraitsint_typeβTraits::int_typepos_typeβTraits::pos_typeoff_typeβTraits::off_type
Member functions
State functions
goodβ checks if no error has occurred i.e. I/O operations are available (public member function ofstd::basic_ios<CharT,Traits>)eofβ checks if end-of-file has been reached (public member function ofstd::basic_ios<CharT,Traits>)failβ checks if an error has occurred (public member function ofstd::basic_ios<CharT,Traits>)badβ checks if a non-recoverable error has occurred (public member function ofstd::basic_ios<CharT,Traits>)operator!β checks if an error has occurred (synonym offail()) (public member function ofstd::basic_ios<CharT,Traits>)operator boolβ checks if no error has occurred (synonym of!fail()) (public member function ofstd::basic_ios<CharT,Traits>)rdstateβ returns state flags (public member function ofstd::basic_ios<CharT,Traits>)setstateβ sets state flags (public member function ofstd::basic_ios<CharT,Traits>)clearβ modifies state flags (public member function ofstd::basic_ios<CharT,Traits>)
Formatting
copyfmtβ copies formatting information (public member function ofstd::basic_ios<CharT,Traits>)fillβ manages the fill character (public member function ofstd::basic_ios<CharT,Traits>)
Miscellaneous
exceptionsβ manages exception mask (public member function ofstd::basic_ios<CharT,Traits>)imbueβ sets the locale (public member function ofstd::basic_ios<CharT,Traits>)rdbufβ manages associated stream buffer (public member function ofstd::basic_ios<CharT,Traits>)tieβ manages tied stream (public member function ofstd::basic_ios<CharT,Traits>)narrowβ narrows characters (public member function ofstd::basic_ios<CharT,Traits>)widenβ widens characters (public member function ofstd::basic_ios<CharT,Traits>)
π Inherited from std::ios_base π
Member functions
Formatting
flagsβ manages format flags (public member function ofstd::ios_base)setfβ sets specific format flag (public member function ofstd::ios_base)unsetfβ clears specific format flag (public member function ofstd::ios_base)precisionβ manages decimal precision of floating point operations (public member function ofstd::ios_base)widthβ manages field width (public member function ofstd::ios_base)
Locales
imbueβ sets locale (public member function ofstd::ios_base)getlocβ returns current locale (public member function ofstd::ios_base)
Internal extensible array
xalloc[static]β returns a program-wide unique integer that is safe to use as index topword()andiword()(public static member function ofstd::ios_base)iwordβ resizes the private storage if necessary and access to the long element at the given index (public member function ofstd::ios_base)pwordβ resizes the private storage if necessary and access to the void* element at the given index (public member function ofstd::ios_base)
Miscellaneous
register_callbackβ registers event callback function (public member function ofstd::ios_base)sync_with_stdio[static]β sets whether C++ and C I/O libraries are interoperable (public static member function ofstd::ios_base)
Member classes
failureβ stream exception (public member class ofstd::ios_base)Initβ initializes standard stream objects (public member class ofstd::ios_base)
πΈ Member types and constants πΈ
okay bestie, this part is basically the glossary section β every type the stream pulls in from its base classes plus all the constants that go with them. no cap, you'll want to bookmark this one π
β¨ openmode β stream open mode type β¨
it's a typedef, and it comes with these iconic little constants:
appβ seek to the end of stream before each writebinaryβ open in binary modeinβ open for readingoutβ open for writingtruncβ discard the contents of the stream when openingateβ seek to the end of stream immediately after opennoreplace(C++23) β open in exclusive mode
fr fr, noreplace is the new kid and it only exists since C++23. don't come for me if it's not there on your dusty compiler π
π fmtflags β formatting flags type π
another typedef, and it's giving so many constants. here we go:
decβ use decimal base for integer I/O: seestd::decoctβ use octal base for integer I/O: seestd::octhexβ use hexadecimal base for integer I/O: seestd::hexbasefieldβdec | oct | hex. Useful for masking operationsleftβ left adjustment (adds fill characters to the right): seestd::leftrightβ right adjustment (adds fill characters to the left): seestd::rightinternalβ internal adjustment (adds fill characters to the internal designated point): seestd::internaladjustfieldβleft | right | internal. Useful for masking operationsscientificβ generate floating point types using scientific notation, or hex notation if combined with fixed: seestd::scientificfixedβ generate floating point types using fixed notation, or hex notation if combined with scientific: seestd::fixedfloatfieldβscientific | fixed. Useful for masking operationsboolalphaβ insert and extractbooltype in alphanumeric format: seestd::boolalphashowbaseβ generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: seestd::showbaseshowpointβ generate a decimal-point character unconditionally for floating-point number output: seestd::showpointshowposβ generate a+character for non-negative numeric output: seestd::showposskipwsβ skip leading whitespace before certain input operations: seestd::skipwsunitbufβ flush the output after each output operation: seestd::unitbufuppercaseβ replace certain lowercase letters with their uppercase equivalents in certain output operations: seestd::uppercase
the three*fieldones (basefield,adjustfield,floatfield) are literally just masks for masking operations β they're the group-chat admins of this list π«Ά
π iostate β state of the stream type π
typedef, and these are the mood-ring constants that tell you how your stream is doing:
goodbitβ no errorbadbitβ irrecoverable stream errorfailbitβ input/output operation failed (formatting or extraction error)eofbitβ associated input sequence has reached end-of-file
so when your stream is acting up, checkiostatefirst.badbitis the π one β irrecoverable is literally in the name, bestie.failbitis just "that operation didn't work out" (formatting or extraction error), andeofbitmeans the input sequence hit end-of-file.goodbitis no error, the main character energy we all want β¨
π¦ seekdir β seeking direction type π¦
typedef again, and it's only three constants, we love a low-maintenance king:
begβ the beginning of a streamendβ the ending of a streamcurβ the current position of stream position indicator
π event β specifies event type π
this one's an enum π
β event_callback β callback function type β
and this one's a typedef β the callback function type that pairs with event.
π₯ Notes π₯
the feature-test macro table, and it's short and sweet:
__cpp_lib_spanstreamβ value202106Lβ std(C++23)β featurestd::spanbuf, std::spanstream
so if you're checking whether your library has the goods, that's the macro to look for.202106L, C++23, coveringstd::spanbufandstd::spanstreamπ
aaaand that's the whole page, bestie! π you made it to the end, we're so proud. go forth and stream your spans responsibly π
this little love letter to std::basic_ispanstream(3) came from cppreference.com, version 2024.06.10 β keep it close, cite it proudly, and may your goodbit always be set πΈβ¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms