This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

761
cppdraft/filebuf.md Normal file
View File

@@ -0,0 +1,761 @@
[filebuf]
# 31 Input/output library [[input.output]](./#input.output)
## 31.10 File-based streams [[file.streams]](file.streams#filebuf)
### 31.10.3 Class template basic_filebuf [filebuf]
#### [31.10.3.1](#general) General [[filebuf.general]](filebuf.general)
[🔗](#lib:basic_filebuf)
namespace std {template<class charT, class traits = char_traits<charT>>class basic_filebuf : public basic_streambuf<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using native_handle_type = *implementation-defined*; // see [[file.native]](file.native "31.10.2Native handles")// [[filebuf.cons]](#cons "31.10.3.2Constructors"), constructors/destructor basic_filebuf();
basic_filebuf(const basic_filebuf&) = delete;
basic_filebuf(basic_filebuf&& rhs); virtual ~basic_filebuf(); // [[filebuf.assign]](#assign "31.10.3.3Assignment and swap"), assignment and swap basic_filebuf& operator=(const basic_filebuf&) = delete;
basic_filebuf& operator=(basic_filebuf&& rhs); void swap(basic_filebuf& rhs); // [[filebuf.members]](#members "31.10.3.4Member functions"), membersbool is_open() const;
basic_filebuf* open(const char* s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path::value_type* s,
ios_base::openmode mode); // wide systems only; see [[fstream.syn]](fstream.syn "31.10.1Header <fstream> synopsis") basic_filebuf* open(const string& s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path& s, ios_base::openmode mode);
basic_filebuf* close();
native_handle_type native_handle() const noexcept; protected:// [[filebuf.virtuals]](#virtuals "31.10.3.5Overridden virtual functions"), overridden virtual functions streamsize showmanyc() override;
int_type underflow() override;
int_type uflow() override;
int_type pbackfail(int_type c = traits::eof()) override;
int_type overflow (int_type c = traits::eof()) override;
basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n) override;
pos_type seekoff(off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out) override;
pos_type seekpos(pos_type sp,
ios_base::openmode which = ios_base::in | ios_base::out) override; int sync() override; void imbue(const locale& loc) override; };}
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11028)
The classbasic_filebuf<charT, traits> associates both the input sequence and the output
sequence with a file[.](#general-1.sentence-1)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11034)
The restrictions on reading and writing a sequence controlled by an
object of classbasic_filebuf<charT, traits> are the same as for reading and writing with the C standard libraryFILEs[.](#general-2.sentence-1)
[3](#general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11041)
In particular:
- [(3.1)](#general-3.1)
If the file is not open for reading the input sequence
cannot be read[.](#general-3.1.sentence-1)
- [(3.2)](#general-3.2)
If the file is not open for writing the output
sequence cannot be written[.](#general-3.2.sentence-1)
- [(3.3)](#general-3.3)
A joint file position is maintained for both the input sequence and
the output sequence[.](#general-3.3.sentence-1)
[4](#general-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11055)
An instance ofbasic_filebuf behaves as described in [filebuf] providedtraits::pos_type isfpos<traits::state_type>[.](#general-4.sentence-1)
Otherwise the behavior is undefined[.](#general-4.sentence-2)
[5](#general-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11064)
The file associated with a basic_filebuf has
an associated value of type native_handle_type,
called the native handle ([[file.native]](file.native "31.10.2Native handles")) of that file[.](#general-5.sentence-1)
This native handle can be obtained by calling
the member function native_handle[.](#general-5.sentence-2)
[6](#general-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11071)
For any opened basic_filebuf f,
the native handle returned by f.native_handle() is
invalidated when f.close() is called, or f is destroyed[.](#general-6.sentence-1)
[7](#general-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11076)
In order to support file I/O and multibyte/wide character conversion,
conversions are performed using members of a facet, referred to asa_codecvt in following subclauses, obtained as if byconst codecvt<charT, char, typename traits::state_type>& a_codecvt = use_facet<codecvt<charT, char, typename traits::state_type>>(getloc());
#### [31.10.3.2](#cons) Constructors [[filebuf.cons]](filebuf.cons)
[🔗](#lib:basic_filebuf,constructor)
`basic_filebuf();
`
[1](#cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11093)
*Effects*: Initializes the base class withbasic_streambuf<charT, traits>() ([[streambuf.cons]](streambuf.cons "31.6.3.2Constructors"))[.](#cons-1.sentence-1)
[2](#cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11098)
*Postconditions*: is_open() == false[.](#cons-2.sentence-1)
[🔗](#lib:basic_filebuf,constructor_)
`basic_filebuf(basic_filebuf&& rhs);
`
[3](#cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11109)
*Effects*: It is implementation-defined whether the sequence pointers in *this (eback(), gptr(), egptr(),pbase(), pptr(), epptr()) obtain
the values which rhs had[.](#cons-3.sentence-1)
Whether they do or not, *this and rhs reference separate buffers (if any at all) after the
construction[.](#cons-3.sentence-2)
Additionally *this references the file
which rhs did before the construction, andrhs references no file after the construction[.](#cons-3.sentence-3)
The
openmode, locale and any other state of rhs is also
copied[.](#cons-3.sentence-4)
[4](#cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11123)
*Postconditions*: Let rhs_p refer to the state ofrhs just prior to this construction and let rhs_a refer to the state of rhs just after this construction[.](#cons-4.sentence-1)
- [(4.1)](#cons-4.1)
is_open() == rhs_p.is_open()
- [(4.2)](#cons-4.2)
rhs_a.is_open() == false
- [(4.3)](#cons-4.3)
gptr() - eback() == rhs_p.gptr() - rhs_p.eback()
- [(4.4)](#cons-4.4)
egptr() - eback() == rhs_p.egptr() - rhs_p.eback()
- [(4.5)](#cons-4.5)
pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase()
- [(4.6)](#cons-4.6)
epptr() - pbase() == rhs_p.epptr() - rhs_p.pbase()
- [(4.7)](#cons-4.7)
if (eback()) eback() != rhs_a.eback()
- [(4.8)](#cons-4.8)
if (gptr()) gptr() != rhs_a.gptr()
- [(4.9)](#cons-4.9)
if (egptr()) egptr() != rhs_a.egptr()
- [(4.10)](#cons-4.10)
if (pbase()) pbase() != rhs_a.pbase()
- [(4.11)](#cons-4.11)
if (pptr()) pptr() != rhs_a.pptr()
- [(4.12)](#cons-4.12)
if (epptr()) epptr() != rhs_a.epptr()
[🔗](#lib:basic_filebuf,destructor)
`virtual ~basic_filebuf();
`
[5](#cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11151)
*Effects*: Callsclose()[.](#cons-5.sentence-1)
If an exception occurs during the destruction of the object, including the call to close(), the exception is caught but not rethrown (see [[res.on.exception.handling]](res.on.exception.handling "16.4.6.14Restrictions on exception handling"))[.](#cons-5.sentence-2)
#### [31.10.3.3](#assign) Assignment and swap [[filebuf.assign]](filebuf.assign)
[🔗](#lib:operator=,basic_filebuf)
`basic_filebuf& operator=(basic_filebuf&& rhs);
`
[1](#assign-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11166)
*Effects*: Calls close() then move assigns from rhs[.](#assign-1.sentence-1)
After the
move assignment *this has the observable state it would have had if it
had been move constructed from rhs (see [[filebuf.cons]](#cons "31.10.3.2Constructors"))[.](#assign-1.sentence-2)
[2](#assign-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11172)
*Returns*: *this[.](#assign-2.sentence-1)
[🔗](#lib:swap,basic_filebuf)
`void swap(basic_filebuf& rhs);
`
[3](#assign-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11183)
*Effects*: Exchanges the state of *this and rhs[.](#assign-3.sentence-1)
[🔗](#lib:swap,basic_filebuf_)
`template<class charT, class traits>
void swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
`
[4](#assign-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11196)
*Effects*: Equivalent to x.swap(y)[.](#assign-4.sentence-1)
#### [31.10.3.4](#members) Member functions [[filebuf.members]](filebuf.members)
[🔗](#lib:is_open,basic_filebuf)
`bool is_open() const;
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11209)
*Returns*: true if a previous call toopen succeeded (returned a non-null value) and there has been no intervening
call to close[.](#members-1.sentence-1)
[🔗](#lib:open,basic_filebuf)
`basic_filebuf* open(const char* s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path::value_type* s,
ios_base::openmode mode); // wide systems only; see [[fstream.syn]](fstream.syn "31.10.1Header <fstream> synopsis")
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11226)
*Preconditions*: s points to an NTCTS ([[defns.ntcts]](defns.ntcts "3.36NTCTS"))[.](#members-2.sentence-1)
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11230)
*Effects*: Ifis_open() != false,
returns a null pointer[.](#members-3.sentence-1)
Otherwise,
initializes thefilebuf as required[.](#members-3.sentence-2)
It then opens
the file to which s resolves, if possible,
as if by a call to fopenwith the second argument determined frommode & ~ios_base::ate as indicated in Table [146](#tab:filebuf.open.modes "Table 146: File open modes")[.](#members-3.sentence-3)
If mode is not some combination of flags shown in the table then
the open fails[.](#members-3.sentence-4)
Table [146](#tab:filebuf.open.modes) — File open modes [[tab:filebuf.open.modes]](./tab:filebuf.open.modes)
| [🔗](#tab:filebuf.open.modes-row-1)<br>ios_base flag combination | | | | | | stdio equivalent |
| --- | --- | --- | --- | --- | --- | --- |
| [🔗](#tab:filebuf.open.modes-row-2)<br>binary | in | out | trunc | app | noreplace |
| [🔗](#tab:filebuf.open.modes-row-3) | | + | | | | "w" |
| [🔗](#tab:filebuf.open.modes-row-4) | | + | | | + | "wx" |
| [🔗](#tab:filebuf.open.modes-row-5) | | + | + | | | "w" |
| [🔗](#tab:filebuf.open.modes-row-6) | | + | + | | + | "wx" |
| [🔗](#tab:filebuf.open.modes-row-7) | | + | | + | | "a" |
| [🔗](#tab:filebuf.open.modes-row-8) | | | | + | | "a" |
| [🔗](#tab:filebuf.open.modes-row-9) | + | | | | | "r" |
| [🔗](#tab:filebuf.open.modes-row-10) | + | + | | | | "r+" |
| [🔗](#tab:filebuf.open.modes-row-11) | + | + | + | | | "w+" |
| [🔗](#tab:filebuf.open.modes-row-12) | + | + | + | | + | "w+x" |
| [🔗](#tab:filebuf.open.modes-row-13) | + | + | | + | | "a+" |
| [🔗](#tab:filebuf.open.modes-row-14) | + | | | + | | "a+" |
| [🔗](#tab:filebuf.open.modes-row-15)<br>+ | | + | | | | "wb" |
| [🔗](#tab:filebuf.open.modes-row-16)<br>+ | | + | | | + | "wbx" |
| [🔗](#tab:filebuf.open.modes-row-17)<br>+ | | + | + | | | "wb" |
| [🔗](#tab:filebuf.open.modes-row-18)<br>+ | | + | + | | + | "wbx" |
| [🔗](#tab:filebuf.open.modes-row-19)<br>+ | | + | | + | | "ab" |
| [🔗](#tab:filebuf.open.modes-row-20)<br>+ | | | | + | | "ab" |
| [🔗](#tab:filebuf.open.modes-row-21)<br>+ | + | | | | | "rb" |
| [🔗](#tab:filebuf.open.modes-row-22)<br>+ | + | + | | | | "r+b" |
| [🔗](#tab:filebuf.open.modes-row-23)<br>+ | + | + | + | | | "w+b" |
| [🔗](#tab:filebuf.open.modes-row-24)<br>+ | + | + | + | | + | "w+bx" |
| [🔗](#tab:filebuf.open.modes-row-25)<br>+ | + | + | | + | | "a+b" |
| [🔗](#tab:filebuf.open.modes-row-26)<br>+ | + | | | + | | "a+b" |
[4](#members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11280)
If the open operation succeeds andios_base::ate is set in mode,
positions the file to the end
(as if by calling fseek(file, 0, SEEK_END), wherefile is the pointer returned by calling fopen)[.](#members-4.sentence-1)[292](#footnote-292 "The macro SEEK_­END is defined, and the function signatures fopen(const char*, const char*) and fseek(FILE*, long, int) are declared, in <cstdio>.")
[5](#members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11297)
If the repositioning operation fails, callsclose() and returns a null pointer to indicate failure[.](#members-5.sentence-1)
[6](#members-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11302)
*Returns*: this if successful, a null pointer otherwise[.](#members-6.sentence-1)
[🔗](#lib:open,basic_filebuf_)
`basic_filebuf* open(const string& s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path& s, ios_base::openmode mode);
`
[7](#members-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11315)
*Returns*: open(s.c_str(), mode);
[🔗](#lib:close,basic_filebuf)
`basic_filebuf* close();
`
[8](#members-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11326)
*Effects*: Ifis_open() == false,
returns a null pointer[.](#members-8.sentence-1)
If a put area exists, callsoverflow(traits::eof()) to flush characters[.](#members-8.sentence-2)
If the last virtual member function called on*this (betweenunderflow,overflow,seekoff,
andseekpos)
wasoverflow then callsa_codecvt.unshift (possibly several times) to determine a termination sequence, inserts those
characters and callsoverflow(traits::eof()) again[.](#members-8.sentence-3)
Finally, regardless of whether any of the preceding calls fails or throws an
exception, the function closes the file
(as if by callingfclose(file))[.](#members-8.sentence-4)
If any of the calls made by the function, including fclose, fails,close fails by returning a null pointer[.](#members-8.sentence-5)
If one of these calls throws an
exception, the exception is caught and rethrown after closing the file[.](#members-8.sentence-6)
[9](#members-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11359)
*Postconditions*: is_open() == false[.](#members-9.sentence-1)
[10](#members-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11363)
*Returns*: this on success, a null pointer otherwise[.](#members-10.sentence-1)
[🔗](#lib:native_handle,basic_filebuf)
`native_handle_type native_handle() const noexcept;
`
[11](#members-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11375)
*Preconditions*: is_open() is true[.](#members-11.sentence-1)
[12](#members-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11379)
*Returns*: The native handle associated with *this[.](#members-12.sentence-1)
[292)](#footnote-292)[292)](#footnoteref-292)
The macro SEEK_END is defined, and the function signaturesfopen(const char*, const char*) andfseek(FILE*, long, int)are declared, in [<cstdio>](cstdio.syn#header:%3ccstdio%3e "31.13.1Header <cstdio> synopsis[cstdio.syn]")[.](#footnote-292.sentence-1)
#### [31.10.3.5](#virtuals) Overridden virtual functions [[filebuf.virtuals]](filebuf.virtuals)
[🔗](#lib:showmanyc,basic_filebuf)
`streamsize showmanyc() override;
`
[1](#virtuals-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11392)
*Effects*: Behaves the same asbasic_streambuf::showmanyc() ([[streambuf.virtuals]](streambuf.virtuals "31.6.3.5Virtual functions"))[.](#virtuals-1.sentence-1)
[2](#virtuals-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11398)
*Remarks*: An
implementation may provide an overriding definition for this function
signature if it can determine whether more characters can be read from the input
sequence[.](#virtuals-2.sentence-1)
[🔗](#lib:underflow,basic_filebuf)
`int_type underflow() override;
`
[3](#virtuals-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11412)
*Effects*: Behaves according to the description ofbasic_streambuf<charT, traits>::underflow(),
with the specialization that a sequence of characters is read from the input
sequence as if by reading from the associated file
into an internal buffer (extern_buf)
and then as if by doing:char extern_buf[XSIZE];char* extern_end;
charT intern_buf[ISIZE];
charT* intern_end;
codecvt_base::result r = a_codecvt.in(state, extern_buf, extern_buf+XSIZE, extern_end,
intern_buf, intern_buf+ISIZE, intern_end);
This shall be done in such a way that the class can recover the
position
(fpos_t)
corresponding to each character betweenintern_buf andintern_end[.](#virtuals-3.sentence-2)
If the value ofr indicates thata_codecvt.in() ran out of space inintern_buf,
retry with a largerintern_buf[.](#virtuals-3.sentence-3)
[🔗](#lib:uflow,basic_filebuf)
`int_type uflow() override;
`
[4](#virtuals-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11453)
*Effects*: Behaves according to the description ofbasic_streambuf<charT, traits>::uflow(),
with the specialization that a sequence of characters is read from the input
with the same method as used byunderflow[.](#virtuals-4.sentence-1)
[🔗](#lib:pbackfail,basic_filebuf)
`int_type pbackfail(int_type c = traits::eof()) override;
`
[5](#virtuals-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11468)
*Effects*: Puts back the character designated by c to the input
sequence, if possible, in one of three ways:
- [(5.1)](#virtuals-5.1)
Iftraits::eq_int_type(c, traits::eof()) returnsfalse and
if the function makes a putback position available
and iftraits::eq(to_char_type(c), gptr()[-1]) returnstrue,
decrements the next pointer for the input sequence,gptr()[.](#virtuals-5.1.sentence-1)
Returns:c[.](#virtuals-5.1.sentence-2)
- [(5.2)](#virtuals-5.2)
Iftraits::eq_int_type(c, traits::eof()) returnsfalse and
if the function makes a putback position available
and if the function is permitted to assign to the putback position,
decrements the next pointer for the input sequence,
and stores c there[.](#virtuals-5.2.sentence-1)
Returns:c[.](#virtuals-5.2.sentence-2)
- [(5.3)](#virtuals-5.3)
Iftraits::eq_int_type(c, traits::eof()) returnstrue,
and if either the input sequence has a putback position available or
the function makes a putback position available,
decrements the next pointer for the input sequence,gptr()[.](#virtuals-5.3.sentence-1)
Returns:traits::not_eof(c)[.](#virtuals-5.3.sentence-2)
[6](#virtuals-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11518)
*Returns*: As specified above, ortraits::eof() to indicate failure[.](#virtuals-6.sentence-1)
[7](#virtuals-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11524)
*Remarks*: Ifis_open() == false,
the function always fails[.](#virtuals-7.sentence-1)
[8](#virtuals-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11530)
The function does not put back a character directly to the input sequence[.](#virtuals-8.sentence-1)
[9](#virtuals-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11533)
If the function can succeed in more than one of these ways, it is
unspecified which way is chosen[.](#virtuals-9.sentence-1)
The function can alter the number of putback positions available as a result of any call[.](#virtuals-9.sentence-2)
[🔗](#lib:overflow,basic_filebuf)
`int_type overflow(int_type c = traits::eof()) override;
`
[10](#virtuals-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11545)
*Effects*: Behaves according to the description ofbasic_streambuf<charT, traits>::overflow(c),
except that the behavior of “consuming characters” is performed by first
converting as if by:charT* b = pbase();
charT* p = pptr();
charT* end;char xbuf[XSIZE];char* xbuf_end;
codecvt_base::result r = a_codecvt.out(state, b, p, end, xbuf, xbuf+XSIZE, xbuf_end); and then
- [(10.1)](#virtuals-10.1)
If r == codecvt_base::error then fail[.](#virtuals-10.1.sentence-1)
- [(10.2)](#virtuals-10.2)
If r == codecvt_base::noconv then output characters fromb up to (and not including) p[.](#virtuals-10.2.sentence-1)
- [(10.3)](#virtuals-10.3)
If r == codecvt_base::partial then output to the file characters fromxbuf up to xbuf_end, and repeat using characters fromend to p[.](#virtuals-10.3.sentence-1)
If output fails, fail (without repeating)[.](#virtuals-10.3.sentence-2)
- [(10.4)](#virtuals-10.4)
Otherwise output from xbuf to xbuf_end, and fail if output fails[.](#virtuals-10.4.sentence-1)
At this point if b != p and b == end (xbuf isn't large
enough) then increase XSIZE and repeat from the beginning[.](#virtuals-10.4.sentence-2)
Then establishes an observable checkpoint ([[intro.abstract]](intro.abstract "4.1.2Abstract machine"))[.](#virtuals-10.sentence-2)
[11](#virtuals-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11574)
*Returns*: traits::not_eof(c) to indicate success, andtraits::eof() to indicate failure[.](#virtuals-11.sentence-1)
Ifis_open() == false,
the function always fails[.](#virtuals-11.sentence-2)
[🔗](#lib:setbuf,basic_filebuf)
`basic_streambuf* setbuf(char_type* s, streamsize n) override;
`
[12](#virtuals-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11591)
*Effects*: Ifsetbuf(0, 0) is called on a stream before any I/O has occurred on that stream, the
stream becomes unbuffered[.](#virtuals-12.sentence-1)
Otherwise the results are implementation-defined[.](#virtuals-12.sentence-2)
“Unbuffered” means thatpbase() andpptr() always return null
and output to the file should appear as soon as possible[.](#virtuals-12.sentence-3)
[🔗](#lib:seekoff,basic_filebuf)
`pos_type seekoff(off_type off, ios_base::seekdir way,
ios_base::openmode which
= ios_base::in | ios_base::out) override;
`
[13](#virtuals-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11615)
*Effects*: Letwidth denotea_codecvt.encoding()[.](#virtuals-13.sentence-1)
Ifis_open() == false,
oroff != 0 && width <= 0,
then the positioning operation fails[.](#virtuals-13.sentence-2)
Otherwise, ifway != basic_ios::cur oroff != 0,
and if the last operation was output,
then update the output sequence and write any unshift sequence[.](#virtuals-13.sentence-3)
Next, seek to the new position: ifwidth > 0,
callfseek(file, width * off, whence),
otherwise callfseek(file, 0, whence)[.](#virtuals-13.sentence-4)
[14](#virtuals-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11639)
*Returns*: A newly constructedpos_type object that stores the resultant
stream position, if possible[.](#virtuals-14.sentence-1)
If the positioning operation fails, or
if the object cannot represent the resultant stream position,
returnspos_type(off_type(-1))[.](#virtuals-14.sentence-2)
[15](#virtuals-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11650)
*Remarks*: “The last operation was output” means either
the last virtual operation was overflow or
the put buffer is non-empty[.](#virtuals-15.sentence-1)
“Write any unshift sequence” means,
ifwidth is less than zero then calla_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end) and output the resulting unshift sequence[.](#virtuals-15.sentence-2)
The function determines one of three values for the
argument whence, of typeint,
as indicated in Table [147](#tab:filebuf.seekoff "Table 147: seekoff effects")[.](#virtuals-15.sentence-3)
Table [147](#tab:filebuf.seekoff) — seekoff effects [[tab:filebuf.seekoff]](./tab:filebuf.seekoff)
| [🔗](#tab:filebuf.seekoff-row-1)<br>**way Value** | **stdio Equivalent** |
| --- | --- |
| [🔗](#tab:filebuf.seekoff-row-2)<br>basic_ios::beg | SEEK_SET |
| [🔗](#tab:filebuf.seekoff-row-3)<br>basic_ios::cur | SEEK_CUR |
| [🔗](#tab:filebuf.seekoff-row-4)<br>basic_ios::end | SEEK_END |
[🔗](#lib:seekpos,basic_filebuf)
`pos_type seekpos(pos_type sp,
ios_base::openmode which
= ios_base::in | ios_base::out) override;
`
[16](#virtuals-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11682)
Alters the file position, if possible, to correspond to the position
stored in sp (as described below)[.](#virtuals-16.sentence-1)
Altering the file position performs as follows:
| [1.](#virtuals-16.1) | if (om & ios_base::out) != 0, then update the output sequence and write any unshift sequence; |
| --- | --- |
| [2.](#virtuals-16.2) | set the file position to sp as if by a call to fsetpos; |
| [3.](#virtuals-16.3) | if (om & ios_base::in) != 0, then update the input sequence; |
where om is the open mode passed to the last call toopen()[.](#virtuals-16.sentence-2)
The operation fails ifis_open() returns false[.](#virtuals-16.sentence-3)
[17](#virtuals-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11705)
If sp is an invalid stream position, or if the function positions
neither sequence, the positioning operation fails[.](#virtuals-17.sentence-1)
If sp has not been obtained by a previous successful call to one of
the positioning functions
(seekoff orseekpos)
on the same file the effects are undefined[.](#virtuals-17.sentence-2)
[18](#virtuals-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11715)
*Returns*: sp on success[.](#virtuals-18.sentence-1)
Otherwise returnspos_type(off_type(-1))[.](#virtuals-18.sentence-2)
[🔗](#lib:sync,basic_filebuf)
`int sync() override;
`
[19](#virtuals-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11729)
*Effects*: If a put area exists, callsfilebuf::overflow to write the characters to the file,
then flushes the file as if by calling fflush(file)[.](#virtuals-19.sentence-1)
If a get area exists, the effect is implementation-defined[.](#virtuals-19.sentence-2)
[🔗](#lib:imbue,basic_filebuf)
`void imbue(const locale& loc) override;
`
[20](#virtuals-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11745)
*Preconditions*: If the file is not positioned at its beginning and the encoding of the current
locale as determined bya_codecvt.encoding() is state-dependent ([[locale.codecvt.virtuals]](locale.codecvt.virtuals "28.3.4.2.5.3Virtual functions"))
then that facet is the same as
the corresponding facet of loc[.](#virtuals-20.sentence-1)
[21](#virtuals-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11754)
*Effects*: Causes characters inserted or extracted after this call
to be converted according to loc until another call ofimbue[.](#virtuals-21.sentence-1)
[22](#virtuals-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11760)
*Remarks*: This may require reconversion of previously converted characters[.](#virtuals-22.sentence-1)
This in turn may require the implementation to be able to reconstruct
the original contents of the file[.](#virtuals-22.sentence-2)