std::basic_spanstream(3)
π C++ Standard Library: std::basic_spanstream π
okay bestie, welcome to the std::basic_spanstream(3) page β this is the fixed-buffer stream class template, and it is serving input/output realness since C++23. no cap, let's get into it. π
π NAME π
std::basic_spanstreamβ yep, the name is literallystd::basic_spanstream, and that's the whole NAME moment. iconic behavior, honestly.
πΈ Synopsis πΈ
Defined in header <spanstream> β¨
template<
class CharT,
class Traits = std::char_traits<CharT>
> class basic_spanstream
: public basic_iostream<CharT, Traits>
This whole class template is since C++23 π«Ά β including that Traits = std::char_traits<CharT> default. The class template std::basic_spanstream implements input and output operations on streams based on fixed buffers. periodt.
At the low level, the class essentially wraps a raw device implementation of std::basic_spanbuf into a higher-level interface of std::basic_iostream. The complete interface to unique std::basic_spanbuf members is provided. π
There's an inheritance diagram, and its file is std-basic spanstream-inheritance.svg β it's labeled Inheritance diagram. πΈ
Several typedefs for common character types are provided:
Defined in header <spanstream>
std::spanstreamβ defined asstd::basic_spanstream<char>std::wspanstreamβ defined asstd::basic_spanstream<wchar_t>
π Member types π
char_typeβCharTtraits_typeβTraits; the program is ill-formed ifTraits::char_typeis notCharT.int_typeβTraits::int_typepos_typeβTraits::pos_typeoff_typeβTraits::off_type
π¦ Data members π¦
sb(private) β the wrappedstd::basic_spanbuf. (exposition-only member object*)
π Member functions π
constructorβ constructs thebasic_spanstream. (C++23, public member function)destructorβ destroys thebasic_spanstream. (C++23,[virtual]virtual public member function)operator=β move-assigns thebasic_spanstream. (C++23, public member function)swapβ swaps twobasic_spanstreamobjects. (C++23, public member function)rdbufβ obtains the address of the wrapped raw span device object. (C++23, public member function)
π Underlying buffer operations π
spanβ gets or sets the underlying buffer of the wrapped span device object. (C++23, public member function)
π₯ Non-member functions π₯
std::swap(std::basic_spanstream)β specializes thestd::swapalgorithm. (C++23, 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_ostream π¦
Member functions
Formatted output
operator<<β inserts formatted data. (public member function ofstd::basic_ostream<CharT,Traits>)
Unformatted output
putβ inserts a character. (public member function ofstd::basic_ostream<CharT,Traits>)writeβ inserts blocks of characters. (public member function ofstd::basic_ostream<CharT,Traits>)
Positioning
tellpβ returns the output position indicator. (public member function ofstd::basic_ostream<CharT,Traits>)seekpβ sets the output position indicator. (public member function ofstd::basic_ostream<CharT,Traits>)
Miscellaneous
flushβ synchronizes with the underlying storage device. (public member function ofstd::basic_ostream<CharT,Traits>)
Member classes
sentryβ implements basic logic for preparation of the stream for output operations. (public member class ofstd::basic_ostream<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β returns a program-wide unique integer that is safe to use as index topword()andiword(). ([static], public static member function ofstd::ios_base)iwordβ resizes the private storage if necessary and access to thelongelement at the given index. (public member function ofstd::ios_base)pwordβ resizes the private storage if necessary and access to thevoid*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β sets whether C++ and C I/O libraries are interoperable. ([static], 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)
openmode (typedef) β the stream open mode type π
Here's the whole squad of constants that come with it:
appβ seek to the end of the 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 the stream immediately after opennoreplace(C++23) β open in exclusive mode
fmtflags (typedef) β the formatting flags type β¨
And these are the constants that ride with it:
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 withfixed: seestd::scientificfixedβ generate floating point types using fixed notation, or hex notation if combined withscientific: 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
iostate (typedef) β the state of the stream type π©Ί
Its constants, bestie:
goodbitβ no errorbadbitβ irrecoverable stream errorfailbitβ input/output operation failed (formatting or extraction error)eofbitβ associated input sequence has reached end-of-file
seekdir (typedef) β the seeking direction type π§
begβ the beginning of a streamendβ the ending of a streamcurβ the current position of stream position indicator
event (enum) β specifies event type π
event_callback (typedef) β callback function type π
π Notes π
Feature-test macro time, and it's giving "look it up":
__cpp_lib_spanstreamβ value202106L, since std(C++23), feature:std::spanbuf,std::spanstream
okay that's literally the whole page, you ate that π go forth and spanstream responsibly, bestie π¦
β¨ xoxo, sourced from http://cppreference.com, dated 2024.06.10, on the page std::basic_spanstream(3) β slay β¨
π¦ 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