std::basic_ispanstream(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ¦‹ 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 β€” CharT
  • traits_type β€” Traits; the program is ill-formed if Traits::char_type is not CharT. (important!!)
  • int_type β€” Traits::int_type
  • pos_type β€” Traits::pos_type
  • off_type β€” Traits::off_type

πŸŽ€ Data members πŸŽ€

  • sb (private) β€” the wrapped std::basic_spanbuf. It's an exposition-only member object*.

πŸ’… Member functions πŸ’…

  • constructor (C++23) β€” constructs the basic_ispanstream (public member function)
  • destructor [virtual] (C++23) β€” destroys the basic_ispanstream (virtual public member function)
  • operator= (C++23) β€” move-assignments the basic_ispanstream (public member function)
  • swap (C++23) β€” swaps two basic_ispanstream objects (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 the std::swap algorithm (function template)

🌈 Inherited from std::basic_istream 🌈

Member functions

Formatted input

  • operator>> β€” extracts formatted data (public member function of std::basic_istream<CharT,Traits>)

Unformatted input

  • get β€” extracts characters (public member function of std::basic_istream<CharT,Traits>)
  • peek β€” reads the next character without extracting it (public member function of std::basic_istream<CharT,Traits>)
  • unget β€” unextracts a character (public member function of std::basic_istream<CharT,Traits>)
  • putback β€” puts a character into input stream (public member function of std::basic_istream<CharT,Traits>)
  • getline β€” extracts characters until the given character is found (public member function of std::basic_istream<CharT,Traits>)
  • ignore β€” extracts and discards characters until the given character is found (public member function of std::basic_istream<CharT,Traits>)
  • read β€” extracts blocks of characters (public member function of std::basic_istream<CharT,Traits>)
  • readsome β€” extracts already available blocks of characters (public member function of std::basic_istream<CharT,Traits>)
  • gcount β€” returns number of characters extracted by last unformatted input operation (public member function of std::basic_istream<CharT,Traits>)

Positioning

  • tellg β€” returns the input position indicator (public member function of std::basic_istream<CharT,Traits>)
  • seekg β€” sets the input position indicator (public member function of std::basic_istream<CharT,Traits>)

Miscellaneous

  • sync β€” synchronizes with the underlying storage device (public member function of std::basic_istream<CharT,Traits>)

Member classes

  • sentry β€” implements basic logic for preparation of the stream for input operations (public member class of std::basic_istream<CharT,Traits>)

πŸ’œ Inherited from std::basic_ios πŸ’œ

Member types

  • char_type β€” CharT
  • traits_type β€” Traits
  • int_type β€” Traits::int_type
  • pos_type β€” Traits::pos_type
  • off_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 of std::basic_ios<CharT,Traits>)
  • eof β€” checks if end-of-file has been reached (public member function of std::basic_ios<CharT,Traits>)
  • fail β€” checks if an error has occurred (public member function of std::basic_ios<CharT,Traits>)
  • bad β€” checks if a non-recoverable error has occurred (public member function of std::basic_ios<CharT,Traits>)
  • operator! β€” checks if an error has occurred (synonym of fail()) (public member function of std::basic_ios<CharT,Traits>)
  • operator bool β€” checks if no error has occurred (synonym of !fail()) (public member function of std::basic_ios<CharT,Traits>)
  • rdstate β€” returns state flags (public member function of std::basic_ios<CharT,Traits>)
  • setstate β€” sets state flags (public member function of std::basic_ios<CharT,Traits>)
  • clear β€” modifies state flags (public member function of std::basic_ios<CharT,Traits>)

Formatting

  • copyfmt β€” copies formatting information (public member function of std::basic_ios<CharT,Traits>)
  • fill β€” manages the fill character (public member function of std::basic_ios<CharT,Traits>)

Miscellaneous

  • exceptions β€” manages exception mask (public member function of std::basic_ios<CharT,Traits>)
  • imbue β€” sets the locale (public member function of std::basic_ios<CharT,Traits>)
  • rdbuf β€” manages associated stream buffer (public member function of std::basic_ios<CharT,Traits>)
  • tie β€” manages tied stream (public member function of std::basic_ios<CharT,Traits>)
  • narrow β€” narrows characters (public member function of std::basic_ios<CharT,Traits>)
  • widen β€” widens characters (public member function of std::basic_ios<CharT,Traits>)

πŸ‘‘ Inherited from std::ios_base πŸ‘‘

Member functions

Formatting

  • flags β€” manages format flags (public member function of std::ios_base)
  • setf β€” sets specific format flag (public member function of std::ios_base)
  • unsetf β€” clears specific format flag (public member function of std::ios_base)
  • precision β€” manages decimal precision of floating point operations (public member function of std::ios_base)
  • width β€” manages field width (public member function of std::ios_base)

Locales

  • imbue β€” sets locale (public member function of std::ios_base)
  • getloc β€” returns current locale (public member function of std::ios_base)

Internal extensible array

  • xalloc [static] β€” returns a program-wide unique integer that is safe to use as index to pword() and iword() (public static member function of std::ios_base)
  • iword β€” resizes the private storage if necessary and access to the long element at the given index (public member function of std::ios_base)
  • pword β€” resizes the private storage if necessary and access to the void* element at the given index (public member function of std::ios_base)

Miscellaneous

  • register_callback β€” registers event callback function (public member function of std::ios_base)
  • sync_with_stdio [static] β€” sets whether C++ and C I/O libraries are interoperable (public static member function of std::ios_base)

Member classes

  • failure β€” stream exception (public member class of std::ios_base)
  • Init β€” initializes standard stream objects (public member class of std::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 write
  • binary β€” open in binary mode
  • in β€” open for reading
  • out β€” open for writing
  • trunc β€” discard the contents of the stream when opening
  • ate β€” seek to the end of stream immediately after open
  • noreplace (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: see std::dec
  • oct β€” use octal base for integer I/O: see std::oct
  • hex β€” use hexadecimal base for integer I/O: see std::hex
  • basefield β€” dec | oct | hex. Useful for masking operations
  • left β€” left adjustment (adds fill characters to the right): see std::left
  • right β€” right adjustment (adds fill characters to the left): see std::right
  • internal β€” internal adjustment (adds fill characters to the internal designated point): see std::internal
  • adjustfield β€” left | right | internal. Useful for masking operations
  • scientific β€” generate floating point types using scientific notation, or hex notation if combined with fixed: see std::scientific
  • fixed β€” generate floating point types using fixed notation, or hex notation if combined with scientific: see std::fixed
  • floatfield β€” scientific | fixed. Useful for masking operations
  • boolalpha β€” insert and extract bool type in alphanumeric format: see std::boolalpha
  • showbase β€” generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: see std::showbase
  • showpoint β€” generate a decimal-point character unconditionally for floating-point number output: see std::showpoint
  • showpos β€” generate a + character for non-negative numeric output: see std::showpos
  • skipws β€” skip leading whitespace before certain input operations: see std::skipws
  • unitbuf β€” flush the output after each output operation: see std::unitbuf
  • uppercase β€” replace certain lowercase letters with their uppercase equivalents in certain output operations: see std::uppercase
the three *field ones (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 error
  • badbit β€” irrecoverable stream error
  • failbit β€” input/output operation failed (formatting or extraction error)
  • eofbit β€” associated input sequence has reached end-of-file
so when your stream is acting up, check iostate first. badbit is the πŸ’€ one β€” irrecoverable is literally in the name, bestie. failbit is just "that operation didn't work out" (formatting or extraction error), and eofbit means the input sequence hit end-of-file. goodbit is 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 stream
  • end β€” the ending of a stream
  • cur β€” 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 β€” value 202106L β€” std (C++23) β€” feature std::spanbuf, std::spanstream
so if you're checking whether your library has the goods, that's the macro to look for. 202106L, C++23, covering std::spanbuf and std::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