std::basic_spanbuf(3)
π NAME π
std::basic_spanbuf - std::basic_spanbuf
okay bestie, welcome to the std::basic_spanbuf(3) page from the C++ Standard Libary β yes, that's the manual name, and yes, we're keeping it exactly as the page says. This is the group chat for a span-backed streambuf, and we're gonna cover every single detail. periodt. π
β¨ Synopsis β¨
Defined in header <spanstream>:
template<
class CharT,
class Traits = std::char_traits<CharT> (since C++23)
> class basic_spanbuf
: public std::basic_streambuf<CharT, Traits>
std::basic_spanbuf is a std::basic_streambuf whose associated character sequence is a memory-resident sequence of arbitrary characters, which can be initialized from or made available as an instance of std::span<CharT>.
The way that std::basic_spanbuf does I/O is on a fixed buffer, and therefore it does not attempt to obtain a new buffer when the underlying buffer is exhausted. no cap, it stays in its lane. π«Ά
Several typedefs for common character types are provided:
Defined in header <spanstream>:
std::spanbufβstd::basic_spanbuf<char>std::wspanbufβstd::basic_spanbuf<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 π«§
mod(private) β astd::ios_base::openmoderecording the open mode. (exposition-only member object*)buf(private) β astd::span<CharT>referencing the underlying buffer. (exposition-only member object*)
π Member functions π
π Public member functions π
constructorβ constructs abasic_spanbufobject (C++23) (public member function)destructor[virtual]β destroys thebasic_spanbufobject (C++23) (virtual public member function)operator=β assigns abasic_spanbufobject (C++23) (public member function)swapβ swaps twobasic_spanbufobjects (C++23) (public member function)spanβ obtains or initializes an underlying buffer according to mode (C++23) (public member function)
π‘οΈ Protected member functions π‘οΈ
setbuf[virtual]β attempts to replace the controlled character sequence with an array (C++23) (virtual protected member function)seekoff[virtual]β repositions the next pointer in the input sequence, output sequence, or both, using relative addressing (C++23) (virtual protected member function)seekpos[virtual]β repositions the next pointer in the input sequence, output sequence, or both using absolute addressing (C++23) (virtual protected member function)
π Non-member functions π
std::swap(std::basic_spanbuf)β specializes thestd::swapalgorithm (C++23) (function template)
π Inherited from std::basic_streambuf π
π 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
πΈ Member functions πΈ
destructor[virtual]β destructs thebasic_streambufobject (virtual public member function ofstd::basic_streambuf<CharT,Traits>)
Locales
pubimbueβ invokesimbue()(public member function ofstd::basic_streambuf<CharT,Traits>)getlocβ obtains a copy of the associated locale (public member function ofstd::basic_streambuf<CharT,Traits>)
Positioning
pubsetbufβ invokessetbuf()(public member function ofstd::basic_streambuf<CharT,Traits>)pubseekoffβ invokesseekoff()(public member function ofstd::basic_streambuf<CharT,Traits>)pubseekposβ invokesseekpos()(public member function ofstd::basic_streambuf<CharT,Traits>)pubsyncβ invokessync()(public member function ofstd::basic_streambuf<CharT,Traits>)
Get area
in_availβ obtains the number of characters immediately available in the get area (public member function ofstd::basic_streambuf<CharT,Traits>)snextcβ advances the input sequence, then reads one character without advancing again (public member function ofstd::basic_streambuf<CharT,Traits>)sbumpcβ reads one character from the input sequence and advances the sequence (public member function ofstd::basic_streambuf<CharT,Traits>)stosscβ reads one character from the input sequence and advances the sequence (removed in C++17) (public member function ofstd::basic_streambuf<CharT,Traits>)sgetcβ reads one character from the input sequence without advancing the sequence (public member function ofstd::basic_streambuf<CharT,Traits>)sgetnβ invokesxsgetn()(public member function ofstd::basic_streambuf<CharT,Traits>)
Put area
sputcβ writes one character to the put area and advances the next pointer (public member function ofstd::basic_streambuf<CharT,Traits>)sputnβ invokesxsputn()(public member function ofstd::basic_streambuf<CharT,Traits>)
Putback
sputbackcβ puts one character back in the input sequence (public member function ofstd::basic_streambuf<CharT,Traits>)sungetcβ moves the next pointer in the input sequence back by one (public member function ofstd::basic_streambuf<CharT,Traits>)
π‘οΈ Protected member functions π‘οΈ
constructorβ constructs abasic_streambufobject (protected member function)operator=β replaces abasic_streambufobject (C++11) (protected member function)swapβ swaps twobasic_streambufobjects (C++11) (protected member function)
Locales
imbue[virtual]β changes the associated locale (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)
Positioning
setbuf[virtual]β replaces the buffer with user-defined array, if permitted (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)seekoff[virtual]β repositions the next pointer in the input sequence, output sequence, or both, using relative addressing (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)seekpos[virtual]β repositions the next pointer in the input sequence, output sequence, or both using absolute addressing (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)sync[virtual]β synchronizes the buffers with the associated character sequence (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)
Get area
showmanyc[virtual]β obtains the number of characters available for input in the associated input sequence, if known (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)underflow[virtual]β reads characters from the associated input sequence to the get area (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)uflow[virtual]β reads characters from the associated input sequence to the get area and advances the next pointer (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)xsgetn[virtual]β reads multiple characters from the input sequence (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)eback,gptr,egptrβ returns a pointer to the beginning, current character and the end of the get area (protected member function)gbumpβ advances the next pointer in the input sequence (protected member function)setgβ repositions the beginning, next, and end pointers of the input sequence (protected member function)
Put area
xsputn[virtual]β writes multiple characters to the output sequence (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)overflow[virtual]β writes characters to the associated output sequence from the put area (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)pbase,pptr,epptrβ returns a pointer to the beginning, current character and the end of the put area (protected member function)pbumpβ advances the next pointer of the output sequence (protected member function)setpβ repositions the beginning, next, and end pointers of the output sequence (protected member function)
Putback
pbackfail[virtual]β puts a character back into the input sequence, possibly modifying the input sequence (virtual protected member function ofstd::basic_streambuf<CharT,Traits>)
π Notes π
β οΈ std::basic_spanbuf does not own the underlying buffer. bestie, this is important.
It is the responsibility of programmers to ensure the underlying buffer is in its lifetime when used by a std::basic_spanbuf object. Additional synchronization may be needed if more than one thread operates the same underlying buffer through different std::basic_spanbuf objects.
Feature-test macro:
__cpp_lib_spanstreamβ value202106L, Std(C++23), Featurestd::spanbuf,std::spanstream
π See also π
basic_stringbufβ implements raw string device (class template)strstreambufβ implements raw character array device (class) (deprecated in C++98) (removed in C++26)
π that's the whole page, bestie. source/version: http://cppreference.com; date: 2024.06.10; page: std::basic_spanbuf(3). go be iconic with your fixed buffers π
π¦ 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