Files
cppdraft_translate/cppdraft/fpos.md
2025-10-25 03:02:53 +03:00

120 lines
7.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[fpos]
# 31 Input/output library [[input.output]](./#input.output)
## 31.5 Iostreams base classes [[iostreams.base]](iostreams.base#fpos)
### 31.5.3 Class template fpos [fpos]
#### [31.5.3.1](#general) General [[fpos.general]](fpos.general)
[🔗](#lib:fpos)
namespace std {template<class stateT> class fpos {public:// [[fpos.members]](#members "31.5.3.2Members"), members stateT state() const; void state(stateT); private: stateT *st*; // *exposition only*};}
#### [31.5.3.2](#members) Members [[fpos.members]](fpos.members)
[🔗](#lib:state,fpos)
`void state(stateT s);
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1659)
*Effects*: Assigns s to *st*[.](#members-1.sentence-1)
[🔗](#lib:state,fpos_)
`stateT state() const;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1670)
*Returns*: Current value of *st*[.](#members-2.sentence-1)
#### [31.5.3.3](#operations) Requirements [[fpos.operations]](fpos.operations)
[1](#operations-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1677)
An fpos type specifies file position information[.](#operations-1.sentence-1)
It holds a state object
whose type is equal to the template parameter stateT[.](#operations-1.sentence-2)
Type stateT shall meet
the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [30](utility.arg.requirements#tab:cpp17.defaultconstructible "Table 30: Cpp17DefaultConstructible requirements")),[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)")),[*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")), and[*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements")) requirements[.](#operations-1.sentence-3)
If is_trivially_copy_constructible_v<stateT> is true,
then fpos<stateT> has a trivial copy constructor[.](#operations-1.sentence-4)
If is_trivially_copy_assignable_v<stateT> is true,
then fpos<stateT> has a trivial copy assignment operator[.](#operations-1.sentence-5)
If is_trivially_destructible_v<stateT> is true,
then fpos<stateT> has a trivial destructor[.](#operations-1.sentence-6)
All specializations of fpos meet
the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]"),[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]"),[*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]"),[*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2Template argument requirements[utility.arg.requirements]"),
and [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")) requirements[.](#operations-1.sentence-7)
In addition, the expressions shown in Table [141](#tab:fpos.operations "Table 141: Position type requirements") are valid and have the indicated semantics[.](#operations-1.sentence-8)
In that table,
- [(1.1)](#operations-1.1)
P refers to a specialization of fpos,
- [(1.2)](#operations-1.2)
p and q refer to values
of type P or const P,
- [(1.3)](#operations-1.3)
pl and ql refer to modifiable lvalues of type P,
- [(1.4)](#operations-1.4)
O refers to type streamoff, and
- [(1.5)](#operations-1.5)
o and o2 refer to values
of type streamoff or const streamoff[.](#operations-1.sentence-9)
Table [141](#tab:fpos.operations) — Position type requirements [[tab:fpos.operations]](./tab:fpos.operations)
| [🔗](#tab:fpos.operations-row-1)<br>**Expression** | **Return type** | **Operational** | **Assertion/note** |
| --- | --- | --- | --- |
| [🔗](#tab:fpos.operations-row-2) | | **semantics** | **pre-/post-condition** |
| [🔗](#tab:fpos.operations-row-3)<br>P(o) | P | converts from offset | *Effects*: Value-initializes the state object[.](#tab:fpos.operations-row-3-column-4-sentence-1) |
| [🔗](#tab:fpos.operations-row-4)<br>P p(o); P p = o; | | | *Effects*: Value-initializes the state object[.](#tab:fpos.operations-row-4-column-4-sentence-1)<br> *Postconditions*: p == P(o) is true[.](#tab:fpos.operations-row-4-column-4-sentence-2) |
| [🔗](#tab:fpos.operations-row-5)<br>P() | P | P(0) | |
| [🔗](#tab:fpos.operations-row-6)<br>P p; | | P p(0); | |
| [🔗](#tab:fpos.operations-row-7)<br>O(p) | streamoff | converts to offset | P(O(p)) == p |
| [🔗](#tab:fpos.operations-row-8)<br>p == q | bool | | *Remarks*: For any two values o and o2, if p is obtained from o converted to P or from a copy of such P value and if q is obtained from o2 converted to P or from a copy of such P value, then p == q is true only if o == o2 is true[.](#tab:fpos.operations-row-8-column-4-sentence-1) |
| [🔗](#tab:fpos.operations-row-9)<br>p != q | bool | !(p == q) | |
| [🔗](#tab:fpos.operations-row-10)<br>p + o | P | + offset | *Remarks*: With ql = p + o;, then: ql - o == p |
| [🔗](#tab:fpos.operations-row-11)<br>pl += o | P& | += offset | *Remarks*: With ql = pl; before the +=, then: pl - o == ql |
| [🔗](#tab:fpos.operations-row-12)<br>p - o | P | - offset | *Remarks*: With ql = p - o;, then: ql + o == p |
| [🔗](#tab:fpos.operations-row-13)<br>pl -= o | P& | -= offset | *Remarks*: With ql = pl; before the -=, then: pl + o == ql |
| [🔗](#tab:fpos.operations-row-14)<br>o + p | convertible to P | p + o | P(o + p) == p + o |
| [🔗](#tab:fpos.operations-row-15)<br>p - q | streamoff | distance | p == q + (p - q) |
[2](#operations-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1790)
Stream operations that return a value of typetraits::pos_type returnP(O(-1)) as an invalid value to signal an error[.](#operations-2.sentence-1)
If this value is used as an argument to anyistream,ostream,
orstreambuf member
that accepts a value of typetraits::pos_type then the behavior of that function is undefined[.](#operations-2.sentence-2)