<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 861: Incomplete specification of EqualityComparable for std::forward_list</title>
<meta property="og:title" content="Issue 861: Incomplete specification of EqualityComparable for std::forward_list">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue861.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++11">C++11</a> status.</em></p>
<h3 id="861"><a href="lwg-defects.html#861">861</a>. Incomplete specification of <code>EqualityComparable</code> for <code>std::forward_list</code></h3>
<p><b>Section:</b> 23.2 <a href="https://wg21.link/container.requirements">[container.requirements]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2008-06-24 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#container.requirements">issues</a> in [container.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Table 89, Container requirements, defines <code>operator==</code> in terms of the container
member function <code>size()</code> and the algorithm <code>std::equal</code>:
</p>

<blockquote><p>
<code>==</code> is an equivalence relation. <code>a.size() == b.size() &amp;&amp;
equal(a.begin(), a.end(), b.begin()</code>
</p></blockquote>

<p>
The new container <code>forward_list</code> does not provide a <code>size</code> member function
by design but does provide <code>operator==</code> and <code>operator!=</code> without specifying it's semantic.
</p>
<p>
Other parts of the (sequence) container requirements do also depend on
<code>size()</code>, e.g. <code>empty()</code>
or <code>clear()</code>, but this issue explicitly attempts to solve the missing
<code>EqualityComparable</code> specification,
because of the special design choices of <code>forward_list</code>.
</p>
<p>
I propose to apply one of the following resolutions, which are described as:
</p>

<ol style="list-style-type:upper-alpha">
<li>
Provide a definition, which is optimal for this special container without
previous size test. This choice prevents two <code>O(N)</code> calls of <code>std::distance()</code>
with the corresponding container ranges and instead uses a special
<code>equals</code> implementation which takes two container ranges instead of 1 1/2.
</li>
<li>
The simple fix where the usual test is adapted such that <code>size()</code> is replaced
by <code>distance</code> with corresponding performance disadvantages.
</li>
</ol>
<p>
Both proposal choices are discussed, the preferred choice of the author is
to apply (A).
</p>

<p><i>[
San Francisco:
]</i></p>


<blockquote>
<p>
There's an Option C: change the requirements table to use distance().
</p>
<p>
LWG found Option C acceptable.
</p>
<p>
Martin will draft the wording for Option C.
</p>
</blockquote>

<p><i>[
post San Francisco:
]</i></p>


<blockquote><p>
Martin provided wording for Option C.
</p></blockquote>

<p><i>[
2009-07 Frankfurt
]</i></p>


<blockquote>
<p>
Other operational semantics (see, for example, Tables 82 and 83) are
written in terms of a container's size() member. Daniel to update
proposed resolution C.
</p>
<p><i>[
Howard: Commented out options A and B.
]</i></p>

</blockquote>

<p><i>[
2009-07-26 Daniel updated proposed resolution C.
]</i></p>


<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Mark NAD Editorial. Addressed by
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2986.pdf">N2986</a>.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Reopened.
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2986.pdf">N2986</a>
was rejected in full committee on procedural grounds.
</p></blockquote>

<p><i>[
2010-01-30 Howard updated Table numbers.
]</i></p>


<p><i>[
2010 Pittsburgh:
]</i></p>


<blockquote><p>
Moved to Ready for Pittsburgh.
</p></blockquote>



<p id="res-861"><b>Proposed resolution:</b></p>


<p>
Option (C):
</p>
<blockquote>

<ol>
<li>
<p>
In 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a> change Table 90 -- Container requirements as indicated:
</p>

<ol style="list-style-type:lower-alpha">
<li>
<p>
Change the text in the Assertion/note column in the row for "<code>X u</code>;"
as follows:
</p>

<blockquote><p>
post: <code>u.<del>size() == 0</del><ins>empty() == true</ins></code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Assertion/note column in the row for "<code>X();</code>"
as follows:
</p>

<blockquote><p>
<code>X().<del>size() == 0</del><ins>empty() == true</ins></code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Operational Semantics column in the row for
"<code>a == b</code>" as follows:
</p>
<blockquote><p>
<code>==</code> is an equivalence relation.
<code><del>a.size()</del><ins>distance(a.begin(), a.end())</ins> ==
   <del>b.size()</del><ins>distance(b.begin(), b.end())</ins> &amp;&amp;
equal(a.begin(), a.end(), b.begin())</code>
</p></blockquote>
</li>

<li>
<p>
Add text in the Ass./Note/pre-/post-condition column in the row for
"<code>a == b</code>" as follows:
</p>
<blockquote><p><ins>
<i>Requires:</i> <code>T</code> is <code>EqualityComparable</code>
</ins></p></blockquote>
</li>

<li>
<p>
Change the text in the Operational Semantics column in the row for
"<code>a.size()</code>" as follows:
</p>

<blockquote><p>
<code><del>a.end() - a.begin()</del><ins>distance(a.begin(), a.end())</ins></code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Operational Semantics column in the row for
"<code>a.max_size()</code>" as follows:
</p>

<blockquote><p>
<code><del>size()</del><ins>distance(begin(), end())</ins></code> of the largest
possible container
</p></blockquote>
</li>

<li>
<p>
Change the text in the Operational Semantics column in the row for
"<code>a.empty()</code>" as follows:
</p>

<blockquote><p>
<code><del>a.size() == 0</del><ins>a.begin() == a.end()</ins></code>
</p></blockquote>
</li>
</ol>
</li>

<li>
<p>
In 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a> change Table 93 &mdash; Allocator-aware container requirements as indicated:
</p>

<ol style="list-style-type:lower-alpha">
<li>
<p>
Change the text in the Assertion&#47;note column in the row for "<code>X() &#47;
X u;</code>" as follows:
</p>

<blockquote><p>
<i>Requires:</i> <code>A</code> is <code>DefaultConstructible</code> post: <code><del>u.size() ==
0</del><ins>u.empty() == true</ins></code>, <code>get_allocator() == A()</code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Assertion&#47;note column in the row for "<code>X(m) &#47;
X u(m);</code>" as follows:
</p>

<blockquote><p>
post: <code><del>u.size() == 0</del><ins>u.empty() == true</ins>,
get_allocator() == m</code>
</p></blockquote>
</li>
</ol>
</li>

<li>
<p>
In 23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a> change Table 94 &mdash; Sequence container requirements as indicated:
</p>

<ol style="list-style-type:lower-alpha">
<li>
<p>
Change the text in the Assertion&#47;note column in the row for "<code>X(n,
t) &#47; X a(n, t)</code>" as follows:
</p>

<blockquote><p>
post: <code><del>size()</del><ins>distance(begin(), end())</ins> == n [..]</code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Assertion&#47;note column in the row for "<code>X(i,
j) &#47; X a(i, j)</code>" as follows:
</p>

<blockquote><p>
[..] post: <del><code>size() ==</code> distance between <code>i</code> and
<code>j</code></del><ins><code>distance(begin(), end()) == distance(i, j)</code></ins> [..]
</p></blockquote>
</li>

<li>
<p>
Change the text in the Assertion&#47;note column in the row for
"<code>a.clear()</code>" as follows:
</p>
<blockquote><p>
<code><ins>a.</ins>erase(<ins>a.</ins>begin(), <ins>a.</ins>end())</code> post:
<code><del>size() == 0</del><ins>a.empty() == true</ins></code>
</p></blockquote>
</li>
</ol>
</li>

<li>
<p>
In 23.2.7 <a href="https://wg21.link/associative.reqmts">[associative.reqmts]</a> change Table 96 &mdash; Associative container requirements as indicated:
</p>

<p><i>[
Not every occurrence of <code>size()</code> was replaced, because all current
associative containers
have a <code>size</code>. The following changes ensure consistency regarding the
semantics of "<code>erase</code>"
for all tables and adds some missing objects
]</i></p>


<ol style="list-style-type:lower-alpha">

<li>
<p>
Change the text in the Complexity column in the row for <code>X(i,j,c)&#47;Xa(i,j,c);</code> 
as follows:
</p>

<blockquote><p>
<code>N</code> log <code>N</code> in general (<code>N</code> <ins><code> == distance(i,
j)</code></ins><del>is the distance from <code>i</code> to <code>j</code></del>); ...
</p></blockquote>

</li>

<li>
<p>
Change the text in the Complexity column in the row for
"<code>a.insert(i, j)</code>" as follows:
</p>
<blockquote><p>
<code>N log(<ins>a.</ins>size() + N)</code> <del>(<code>N</code> is the distance from <code>i</code> to
<code>j</code>)</del><ins> where <code>N == distance(i, j)</code></ins>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Complexity column in the row for
"<code>a.erase(k)</code>" as follows:
</p>
<blockquote><p>
<code>log(<ins>a.</ins>size()) + <ins>a.</ins>count(k)</code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Complexity column in the row for
"<code>a.erase(q1, q2)</code>" as follows:
</p>

<blockquote><p>
<code>log(<ins>a.</ins>size()) + N</code> where <code>N</code> <del>is the distance from <code>q1</code>
to <code>q2</code></del>
   <ins><code>== distance(q1, q2)</code></ins>.
</p></blockquote>
</li>

<li>
<p>
Change the text in the Assertion&#47;note column in the row for
"<code>a.clear()</code>" as follows:
</p>

<blockquote><p>
<code><ins>a.</ins>erase(a.begin(),a.end())</code> post: <code><del>size() ==
0</del><ins>a.empty() == true</ins></code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Complexity column in the row for "<code>a.clear()</code>"
as follows:
</p>

<blockquote><p>
linear in <code><ins>a.</ins>size()</code>
</p></blockquote>
</li>

<li>
<p>
Change the text in the Complexity column in the row for
"<code>a.count(k)</code>" as follows:
</p>

<blockquote><p>
<code>log(<ins>a.</ins>size()) + <ins>a.</ins>count(k)</code>
</p></blockquote>
</li>
</ol>
</li>

<li>
<p>
In 23.2.8 <a href="https://wg21.link/unord.req">[unord.req]</a> change Table 98 &mdash; Unordered associative container requirements as indicated:
</p>
<p><i>[
The same rational as for Table 96 applies here
]</i></p>


<ol style="list-style-type:lower-alpha">
<li>
<p>
Change the text in the Assertion&#47;note column in the row for
"<code>a.clear()</code>" as follows:
</p>

<blockquote><p>
[..] Post: <code>a.<del>size() == 0</del><ins>empty() == true</ins></code>
</p></blockquote>
</li>
</ol>
</li>
</ol>


</blockquote>





</body>
</html>
