<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3115: Unclear description for algorithm includes</title>
<meta property="og:title" content="Issue 3115: Unclear description for algorithm includes">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3115.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#Resolved">Resolved</a> status.</em></p>
<h3 id="3115"><a href="lwg-defects.html#3115">3115</a>. Unclear description for algorithm <code>includes</code></h3>
<p><b>Section:</b> 26.8.7.2 <a href="https://wg21.link/includes">[includes]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2018-05-24 <b>Last modified:</b> 2020-09-06</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#includes">issues</a> in [includes].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
26.8.7.2 <a href="https://wg21.link/includes">[includes]</a>/1 states:
</p>
<blockquote><p>
<i>Returns:</i> <code>true</code> if <code>[first2, last2)</code> is empty or if every element in the range <code>[first2, last2)</code>
is contained in the range <code>[first1, last1)</code>. Returns <code>false</code> otherwise.
</p></blockquote>
<p>
but this program:
</p>
<blockquote><pre>
#include &lt;algorithm&gt;
#include &lt;array&gt;

int main() {
  std::array&lt;int, 1&gt; a{1};
  std::array&lt;int, 3&gt; b{1,1,1};
  return std::includes(a.begin(), a.end(), b.begin(), b.end());
}
</pre></blockquote>
<p>
<a href="https://wandbox.org/permlink/tClRFr7VquXQNB4x">returns <code>0</code></a> on every implementation I can find, despite
that every element in the range <code>b</code> is contained in the range <code>a</code>. The design intent of the algorithm is
actually to determine if the sorted intersection of the elements from the two ranges &mdash; as would be computed by the
<code>set_intersection</code> algorithm &mdash; is the same sequence as the range <code>[first2, last2)</code>.
The specification should say so.
</p><p>
The complexity bound in 26.8.7.2 <a href="https://wg21.link/includes">[includes]</a>/2 is also unnecessarily high: straightforward implementations perform
at most <code>2 * (last1 - first1)</code> comparisons.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4750">N4750</a>.</p>

<ol>
<li><p>Modify 26.8.7.2 <a href="https://wg21.link/includes">[includes]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class InputIterator1, class InputIterator2&gt;
  constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
                          InputIterator2 first2, InputIterator2 last2);
[&hellip;]
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>true</code> if <ins>and only if</ins> <code>[first2, last2)</code> is <del>empty or if every element
in the range <code>[first2, last2)</code> is contained in the range <code>[first1, last1)</code>. Returns <code>false</code>
otherwise</del><ins>a subsequence of <code>[first1, last1)</code></ins>.
<p/>
-2- <i>Complexity:</i> At most <code>2 * <del>(</del>(last1 - first1)<del> + (last2 - first2)) - 1</del></code> comparisons.
</p>
</blockquote>
</blockquote>
</li>

</ol>
</blockquote>

<p><i>[2018-06-27 after reflector discussion]</i></p>

<p>Priority set to 3. Improved wording as result of that discussion.</p>

<p><i>[2018-11-13; Casey Carter comments]</i></p>

<p>
The acceptance of <a href="https://wg21.link/p0896r4">P0896R4</a> during the San Diego meeting resolves this 
issue: The wording in [includes] includes the PR for LWG 3115.
</p>


<p id="res-3115"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4750">N4750</a>.</p>

<ol>
<li><p>Modify 26.8.7.2 <a href="https://wg21.link/includes">[includes]</a> as indicated:</p>

<blockquote>
<pre>
template&lt;class InputIterator1, class InputIterator2&gt;
  constexpr bool includes(InputIterator1 first1, InputIterator1 last1,
                          InputIterator2 first2, InputIterator2 last2);
[&hellip;]
</pre>
<blockquote>
<p>
-1- <i>Returns:</i> <code>true</code> if <ins>and only if</ins> <code>[first2, last2)</code> is <del>empty or if every element
in the range <code>[first2, last2)</code> is contained in the range <code>[first1, last1)</code>. Returns <code>false</code>
otherwise</del><ins>a subsequence of <code>[first1, last1)</code>. [<i>Note:</i> A sequence <code>S</code> is a <b>subsequence</b>
of another sequence <code>T</code> if <code>S</code> can be obtained from <code>T</code> by removing some, all, or none of <code>T</code>'s
elements and keeping the remaining elements in the same order. &mdash; <i>end note</i>]</ins>.
<p/>
-2- <i>Complexity:</i> At most <code>2 * <del>(</del>(last1 - first1)<del> + (last2 - first2)) - 1</del></code> comparisons.
</p>
</blockquote>
</blockquote>
</li>

</ol>





</body>
</html>
