<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>fpos requirements</title>

<style type="text/css">
  p {text-align:justify}
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  blockquote.note
  {
   background-color:#E0E0E0;
   padding-left: 15px;
   padding-right: 15px;
   padding-top: 1px;
   padding-bottom: 1px;
  }
</style>
</head><body>
<address style="text-align: left;">
Document number: P0759R1<br>
Date: 2018-06-04<br>
Audience: Library Working Group<br>
Author: Daniel Kr&uuml;gler<br>
Reply-to: <a href="mailto:daniel.kruegler@gmail.com">Daniel Kr&uuml;gler</a>
</address>
<hr>
<h1 style="text-align: center;"><tt>fpos</tt> Requirements</h1>

<ul>
<li><a href="#Intro">Introduction</a></li>
<li><a href="#RevisionHistory">Revision History</a></li>
<li><a href="#Discussion">Discussion</a></li>
<li><a href="#Issues_Resolved">Resolved Issues</a></li>
<li><a href="#Proposed_resolution">Proposed Resolution</a></li>
<li><a href="#Bibliography">Bibliography</a></li>
<li><a href="#Akn">Acknowledgements</a></li>
</ul>

<h2><a name="Intro"></a>Introduction</h2>
<p>
This is a plain wording fixing proposal for the table-based requirement set of class template <tt>fpos</tt>. A paper 
is provided instead of drafting wording in the referenced issues, to have more room available for presentation and 
explanation.
<p/>
The wording changes suggested by this paper <em>should not</em> have effects on any existing implementations, because
it mainly intended to clearify several underspecified parts of the current specification. Nonetheless during the analysis
of the paper there occurred some curiosities in the specification that caused to ask some questions to the committee 
which <em>might</em> lead to decisions to change existing implementations, but the author has tried to be as 
conservative as possible in regard to such suggestions.
</p>

<h2><a name="RevisionHistory"></a>Revision History</h2>
<p>
Changes since <a href="http://wg21.link/p0759r0">P0759R0</a>:
</p>
<ul>
<li><p>Rebases to the reference working draft <a href="http://wg21.link/n4750">N4750</a></p></li>
<li><p>Get rid of the expression <tt>q + ol == p</tt> in Table 106 &mdash; "Position type requirements" including the
additionally needed expression symbol <tt>ol</tt> that was needed only to specify the expression <tt>p - q</tt>. The 
author believes that the newly added assertion expression <tt>p == q + (p - q)</tt> is sufficient.</p></li>
<li><p>Add an operational semantics entry <tt>p + o</tt> to the expression row <tt>o + p</tt> in Table 106.</p></li>
</ul>

<h2><a name="Discussion"></a>Discussion</h2>
<p>
This paper revision does not repeat the sections 
<a href="http://wg21.link/p0759r0#Discussion">Discussion</a>,
<a href="http://wg21.link/p0759r0#Discussion.facts">1. Specification Facts</a>,
and <a href="http://wg21.link/p0759r0#Discussion.problems">2. Specification Problems</a>
of its predecessor <a href="http://wg21.link/p0759r0">P0759R0</a>.
<p/>
Please refer to the previous paper regarding general background and (extended) rationale.
</p>

<h2><a name="Issues_Resolved"></a>Resolved Issues</h2>
<p>
If the proposed resolution will be accepted, the following library issues will be resolved:
</p>
<table border="1">
  <tr>
    <th>Number</th>
    <th>Description</th>
    <th>C++17 NB comment</th>
  </tr>
  <tr>
    <td><a href="http://wg21.link/lwg2808">2808</a></td>
    <td>Requirements for <tt>fpos</tt> and <tt>stateT</tt></td>
    <td><a href="http://wg21.link/p0488r0">GB 60</a></td>
  </tr>
  <tr>
    <td><a href="http://wg21.link/lwg2832">2832</a></td>
    <td>&sect;[fpos.operations] strange requirement for <tt>P(i)</tt></td>
    <td>&mdash;</td>
  </tr>
</table> 

<h2><a name="Proposed_resolution"></a>Proposed resolution</h2>

<p>
At some places below, additional markup of the form
</p>
<blockquote class="note">
<p>
[<i>Drafting notes</i>: whatever &mdash; <i>end drafting notes</i>]
</p>
</blockquote>
<p>
is provided, which is <em>not</em> part of the normative wording, but is solely shown to provide additional information 
to the reader about the rationale of the concrete wording.
</p>

<p>
The proposed wording changes refer in all cases to <a href="http://wg21.link/n4750">N4750</a>.
</p>

<ol>
<li><p>Change 30.5.4.2 [fpos.operations] as indicated:</p>

<blockquote>
<p>
-1- <del>Operations specified in Table 112 are permitted.</del> <ins>An <tt>fpos</tt> type specifies file position 
information. It holds a state object whose type is equal to the template parameter <tt>stateT</tt>. Type <tt>stateT</tt>
shall meet the <tt>DefaultConstructible</tt> (Table 22), <tt>CopyConstructible</tt> (Table 24), 
<tt>CopyAssignable</tt> (Table 26), and <tt>Destructible</tt> (Table 27) requirements. If 
<tt>is_trivially_copy_constructible_v&lt;stateT&gt;</tt> is <tt>true</tt>, then <tt>fpos&lt;stateT&gt;</tt> has a 
trivial copy constructor. If <tt>is_trivially_copy_assignable&lt;stateT&gt;</tt> is <tt>true</tt>, then 
<tt>fpos&lt;stateT&gt;</tt> has a trivial copy assignment operator. If <tt>is_trivially_destructible_v&lt;stateT&gt;</tt> 
is <tt>true</tt>, then <tt>fpos&lt;stateT&gt;</tt> has a trivial destructor. All specializations of
<tt>fpos</tt> satisfy the <tt>DefaultConstructible</tt>, <tt>CopyConstructible</tt>, <tt>CopyAssignable</tt>, 
<tt>Destructible</tt>, and <tt>EqualityComparable</tt> (Table 20) requirements. 
In addition, the expressions shown in Table 112 are valid and have the indicated semantics.</ins>
In that table,
</p>
<ol style="list-style-type: none">
<li><p>(1.1) &mdash; <tt>P</tt> refers to an instance of <tt>fpos</tt>,</p></li>
<li><p>(1.2) &mdash; <tt>p</tt> and <tt>q</tt> refer to values of type <tt>P</tt> <ins>or <tt>const P</tt></ins>,</p></li>
<li><p><ins>(1.?) &mdash; <tt>pl</tt> and <tt>ql</tt> refer to modifiable lvalues of type <tt>P</tt>,</ins></p></li>
<li><p>(1.3) &mdash; <tt>O</tt> refers to type <tt>streamoff</tt>,<ins>and</ins></p></li>
<li><p>(1.4) &mdash; <tt>o</tt> refers to a value of type <tt>streamoff</tt> <ins>or <tt>const streamoff</tt></p></li>
<li><p><del>(1.5) &mdash; <tt>sz</tt> refers to a value of type <tt>streamsize</tt> and</del></p></li>
<li><p><del>(1.6) &mdash; <tt>i</tt> refers to a value of type <tt>int</tt>.</del></p></li>
</ol>

<blockquote class="note">
<p>
[<i>Drafting notes</i>: It is recommend to strike the non-normative note in p2 completely. This seems to be very out-dated
wording and what is says is already said in 20.4.1.3 [structure.requirements], in particular in p3+p4 &mdash; 
<i>end drafting notes</i>]
</p>
</blockquote>

<p>
<del>-2- [<i>Note:</i> Every implementation is required to supply overloaded operators on <tt>fpos</tt> objects to satisfy the
requirements of 30.5.4.2 [fpos.operations]. It is unspecified whether these operators are members of <tt>fpos</tt>, 
global operators, or provided in some other way. &mdash; <i>end note</i>]</del>
<p/>
-3- Stream operations that return a value of type <tt>traits::pos_type</tt> return <tt>P(O(-1))</tt> as an invalid value to
signal an error. If this value is used as an argument to any <tt>istream</tt>, <tt>ostream</tt>, or <tt>streambuf</tt> member that
accepts a value of type <tt>traits::pos_type</tt> then the behavior of that function is undefined.
</p>
</blockquote>
</li>

<li><p>Change Table 106 &mdash; "Position type requirements", as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting notes</i>: We can strike the wording about the destructor and <tt>==</tt>, because we
have now the <tt>EqualityComparable</tt> and <tt>Destructible</tt> requirements 
specified in 30.5.4.2 [fpos.operations] &mdash; <i>end drafting notes</i>]
</p>
</blockquote>

<blockquote>
<table border="1">
<caption>Table 106 &mdash; Position type requirements</caption>

<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational semantics</th>
<th>Assertion/note<br/>pre-/post-condition</th>
</tr>

<tr>
<td><del><tt>P(i)</tt></del></td> 
<td><del>&emsp;</del></td>
<td><del>&emsp;</del></td>
<td>
<del><tt>p == P(i)</tt><br/>
note: a destructor is assumed.</del>
</td>
</tr>

<tr>
<td>
<del><tt>P p(i);<br/>
P p = i;</tt></del>
</td>
<td><del>&emsp;</del></td>
<td><del>&emsp;</del></td>
<td><del><i>Postconditions:</i> <tt>p == P(i)</tt>.</del></td>
</tr>

<tr>
<td><tt>P(o)</tt></td>
<td><tt><del>fpos</del><ins>P</ins></tt></td>
<td>converts from <tt>offset</tt></td>
<td><ins><i>Effects:</i> Value-initializes the state object.</ins></td>
</tr>

<tr>
<td>
<ins><tt>P p(o);<br/>
P p = o;</tt></ins>
</td>
<td></td>
<td></td>
<td>
<ins><i>Effects:</i> Value-initializes the state object.</ins><br/>
<ins><i>Postconditions:</i> <tt>p == P(o)</tt></ins>
</td>
</tr>

<tr>
<td>
<ins><tt>P()</tt></ins></td>
<td><ins><tt>P</tt></ins></td>
<td><ins><tt>P(0)</tt></ins></td>
<td>
</td>
</tr>

<tr>
<td>
<ins><tt>P p;</tt></ins></td>
<td></td>
<td><ins><tt>P p(0);</tt></ins></td>
<td></td>
</tr>

<tr>
<td><tt>O(p)</tt></td>
<td><tt>streamoff</tt></td>
<td>converts to <tt>offset</tt></td>
<td><tt>P(O(p)) == p</tt></td>
</tr>

<tr>
<td><del><tt>p == q</tt></del></td>
<td><del>convertible to <tt>bool</tt></del></td>
<td><del>&emsp;</del></td>
<td><del><tt>==</tt> is an equivalence relation</del></td>
</tr>

<tr>
<td><tt>p != q</tt></td>
<td>convertible to <tt>bool</tt></td>
<td><tt>!(p == q)</tt></td>
<td></td>
</tr>

<tr>
<td><tt><del>q =</del> p + o<br/>
<del>p += o</del></tt></td>
<td><tt><del>fpos</del><ins>P</ins></tt></td>
<td><tt>+</tt> offset</td>
<td><ins><i>Remarks:</i> With <tt>ql = p + o;</tt>, then:<br/></ins> 
<tt>q<ins>l</ins> - o == p</tt></td>
</tr>

<tr>
<td><ins><tt>pl += o</tt></ins></td>
<td><ins><tt>P&amp;</tt></ins></td>
<td><ins><tt>+=</tt> offset</ins></td>
<td><ins><i>Remarks:</i> With <tt>ql = pl;</tt> before the <tt>+=</tt>, then:<br/>
<tt>pl - o == ql</tt></ins></td>
</tr>

<tr>
<td><tt><del>q =</del> p - o<br/>
<del>p -= o</del></tt></td>
<td><tt><del>fpos</del><ins>P</ins></tt></td>
<td><tt>-</tt> offset</td>
<td><ins><i>Remarks:</i> With <tt>ql = p - o;</tt>, then:<br/></ins> <tt>q<ins>l</ins> + o == p</tt></td>
</tr>

<tr>
<td><ins><tt>pl -= o</tt></ins></td>
<td><ins><tt>P&amp;</tt></ins></td>
<td><ins><tt>-=</tt> offset</ins></td>
<td><ins><i>Remarks:</i> With <tt>ql = pl;</tt> before the <tt>-=</tt>, then:<br/>
<tt>pl + o == ql</tt></ins></td>
</tr>

<tr>
<td><ins><tt>o + p</tt></ins></td> 
<td><ins>convertible to <tt>P</tt></ins></td>
<td><ins><tt>p + o</tt></ins></td>
<td><ins><tt>P(o + p) == p + o</tt></ins></td>
</tr>

<tr>
<td><tt><del>o =</del> p - q</tt></td>
<td><tt>streamoff</tt></td>
<td>distance</td>
<td>
<ins><tt>p == q + (p - q)</tt></ins><br/>
<del><tt>q + o == p</tt></del>
</td>
</tr>

<tr>
<td><del><tt>streamsize(o)<br/>
O(sz)</tt></del></td>
<td><del><tt>streamsize<br/>
streamoff</tt></del></td>
<td><del>converts<br/>
converts</del></td>
<td><del><tt>streamsize(O(sz)) == sz<br/>
streamsize(O(sz)) == sz</tt></del></td>
</tr>

</table>

</blockquote>
</li>

</ol>

<h2><a name="Bibliography"></a>Bibliography</h2>
<p>
<a name="bib-n4750"></a><a href="http://wg21.link/n4750">N4750 Richard Smith: "Working Draft, Standard for Programming Language C++"</a>
</p>

<h2><a name="Akn"></a>Acknowledgements</h2>
<p>
Thanks to Jonathan Wakely, Billy Robert O'Neal III, and Axel Naumann for a review of this proposal and for encouragement to make a little more
changes as I originally believed I should make.
</p>

</body></html>