29 Input/output library [input.output]

29.5 Iostreams base classes [iostreams.base]

29.5.4 Class template fpos [fpos]

namespace std {
  template<class stateT> class fpos {
  public:
    // [fpos.members], members
    stateT state() const;
    void state(stateT);
  private;
    stateT st;                  // exposition only
  };
}

29.5.4.1 Members [fpos.members]

void state(stateT s);
Effects: Assigns s to st.
stateT state() const;
Returns: Current value of st.

29.5.4.2 Requirements [fpos.operations]

An fpos type specifies file position information.
It holds a state object whose type is equal to the template parameter stateT.
Type stateT shall meet the Cpp17DefaultConstructible (Table 27), Cpp17CopyConstructible (Table 29), Cpp17CopyAssignable (Table 31), and Cpp17Destructible (Table 32) requirements.
If is_­trivially_­copy_­constructible_­v<stateT> is true, then fpos<stateT> has a trivial copy constructor.
If is_­trivially_­copy_­assignable<stateT> is true, then fpos<stateT> has a trivial copy assignment operator.
If is_­trivially_­destructible_­v<stateT> is true, then fpos<stateT> has a trivial destructor.
All specializations of fpos meet the Cpp17DefaultConstructible, Cpp17CopyConstructible, Cpp17CopyAssignable, Cpp17Destructible, and Cpp17EqualityComparable (Table 25) requirements.
In addition, the expressions shown in Table 121 are valid and have the indicated semantics.
In that table,
  • P refers to an instance of fpos,
  • p and q refer to values of type P or const P,
  • pl and ql refer to modifiable lvalues of type P,
  • O refers to type streamoff, and
  • o refers to a value of type streamoff or const streamoff.
Table 121: Position type requirements   [tab:fpos.operations]
Expression
Return type
Operational
Assertion/note
semantics
pre-/post-condition
P(o)
P
converts from offset
Effects: Value-initializes the state object.
P p(o);
P p = o;
Effects: Value-initializes the state object.

Postconditions: p == P(o)
P()
P
P(0)
P p;
P p(0);
O(p)
streamoff
converts to offset
P(O(p)) == p
p != q
convertible to bool
!(p == q)
p + o
P
+ offset
Remarks: With ql = p + o;, then: ql - o == p
pl += o
P&
+= offset
Remarks: With ql = pl; before the +=, then: pl - o == ql
p - o
P
- offset
Remarks: With ql = p - o;, then: ql + o == p
pl -= o
P&
-= offset
Remarks: With ql = pl; before the -=, then: pl + o == ql
o + p
convertible to P
p + o
P(o + p) == p + o
p - q
streamoff
distance
p == q + (p - q)
Stream operations that return a value of type traits​::​pos_­type return P(O(-1)) as an invalid value to signal an error.
If this value is used as an argument to any istream, ostream, or streambuf member that accepts a value of type traits​::​pos_­type then the behavior of that function is undefined.