<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2150: Unclear specification of find_end</title>
<meta property="og:title" content="Issue 2150: Unclear specification of find_end">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2150.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++14">C++14</a> status.</em></p>
<h3 id="2150"><a href="lwg-defects.html#2150">2150</a>. Unclear specification of <code>find_end</code></h3>
<p><b>Section:</b> 26.6.8 <a href="https://wg21.link/alg.find.end">[alg.find.end]</a> <b>Status:</b> <a href="lwg-active.html#C++14">C++14</a>
 <b>Submitter:</b> Andrew Koenig <b>Opened:</b> 2012-03-28 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>

<p>
26.6.8 <a href="https://wg21.link/alg.find.end">[alg.find.end]</a> describes the behavior of find_end as returning:
</p>
<blockquote><p>
The last iterator <code>i</code> in the range <code>[first1,last1 - (last2 - first2))</code> such that for any 
nonnegative integer <code>n &lt; (last2 - first2)</code>, the following corresponding conditions hold: 
<code>*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false</code>.
</p></blockquote>
<p>
Does "for any" here mean "for every" or "there exists a"?  I think it means the former, but it could be 
interpreted either way.
<p/>
Daniel: The same problem exists for the following specifications from Clause 26 <a href="https://wg21.link/algorithms">[algorithms]</a>:
</p>
<ol>
<li>26.6.15 <a href="https://wg21.link/alg.search">[alg.search]</a> p2 and p6</li>
<li>26.7.10 <a href="https://wg21.link/alg.reverse">[alg.reverse]</a> p4</li>
<li>26.8.5 <a href="https://wg21.link/alg.partitions">[alg.partitions]</a> p5 and p9</li>
<li>26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a> p5</li>
<li>26.8.3 <a href="https://wg21.link/alg.nth.element">[alg.nth.element]</a> p1</li>
<li>26.8.4.2 <a href="https://wg21.link/lower.bound">[lower.bound]</a> p2</li>
<li>26.8.4.3 <a href="https://wg21.link/upper.bound">[upper.bound]</a> p2</li>
<li>26.8.9 <a href="https://wg21.link/alg.min.max">[alg.min.max]</a> p21 and p23</li>
</ol>

<p><i>[2013-04-20, Bristol]</i></p>


<p>
Unanimous agreement on the wording.
<p/>
Resolution: move to tentatively ready 
</p>

<p><i>[2013-09-29, Chicago]</i></p>


<p>
Apply to Working Paper
</p>


<p id="res-2150"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3376.</p>

<ol>
<li>
<p>Change 26.6.8 <a href="https://wg21.link/alg.find.end">[alg.find.end]</a> p2 as indicated:</p>

<blockquote><pre>
template&lt;class ForwardIterator1, class ForwardIterator2&gt;
ForwardIterator1 
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
         ForwardIterator2 first2, ForwardIterator2 last2);
template&lt;class ForwardIterator1, class ForwardIterator2,
         class BinaryPredicate&gt;
ForwardIterator1
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
         ForwardIterator2 first2, ForwardIterator2 last2,
         BinaryPredicate pred);
</pre><blockquote><p>
[&hellip;]
<p/>
-2- <i>Returns</i>: The last iterator <code>i</code> in the range <code>[first1,last1 - (last2 - first2))</code> such 
that for <del>any</del><ins>every</ins> nonnegative integer <code>n &lt; (last2 - first2)</code>, the following 
corresponding conditions hold: <code>*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false</code>.
Returns <code>last1</code> if <code>[first2,last2)</code> is empty or if no such iterator is found.
</p></blockquote></blockquote>
</li>

<li>
<p>Change 26.6.15 <a href="https://wg21.link/alg.search">[alg.search]</a> p2 and p6 as indicated:</p>

<blockquote><pre>
template&lt;class ForwardIterator1, class ForwardIterator2&gt;
ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
       ForwardIterator2 first2, ForwardIterator2 last2);
template&lt;class ForwardIterator1, class ForwardIterator2,
         class BinaryPredicate&gt;
ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
       ForwardIterator2 first2, ForwardIterator2 last2,
       BinaryPredicate pred);
</pre><blockquote><p>
[&hellip;]
<p/>
-2- <i>Returns</i>: The first iterator <code>i</code> in the range <code>[first1,last1 - (last2-first2))</code> 
such that for <del>any</del><ins>every</ins> nonnegative integer <code>n</code> less than <code>last2 - first2</code> 
the following corresponding conditions hold: <code>*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false</code>. 
Returns <code>first1</code> if <code>[first2,last2)</code> is empty, otherwise returns <code>last1</code> if no such iterator 
is found.
</p></blockquote></blockquote>
<p>
[&hellip;]
</p>
<blockquote><pre>
template&lt;class ForwardIterator, class Size, class T&gt;
ForwardIterator
search_n(ForwardIterator first, ForwardIterator last, Size count,
         const T&amp; value);
template&lt;class ForwardIterator, class Size, class T,
         class BinaryPredicate&gt;
ForwardIterator
search_n(ForwardIterator first, ForwardIterator last, Size count,
         const T&amp; value, BinaryPredicate pred);
</pre><blockquote><p>
[&hellip;]
<p/>
-6- <i>Returns</i>: The first iterator <code>i</code> in the range <code>[first,last-count)</code> such that 
for <del>any</del><ins>every</ins> non-negative integer <code>n</code> less than <code>count</code> the following 
corresponding conditions hold: <code>*(i + n) == value, pred(*(i + n),value) != false</code>. Returns <code>last</code> 
if no such iterator is found.
</p></blockquote></blockquote>
</li>

<li>
<p>Change 26.7.10 <a href="https://wg21.link/alg.reverse">[alg.reverse]</a> p4 as indicated:</p>

<blockquote><pre>
template&lt;class BidirectionalIterator, class OutputIterator&gt;
OutputIterator
reverse_copy(BidirectionalIterator first,
             BidirectionalIterator last, OutputIterator result);
</pre><blockquote><p>
[&hellip;]
<p/>
-4- <i>Effects</i>: Copies the range <code>[first,last)</code> to the range <code>[result,result+(last-first))</code> 
such that for <del>any</del><ins>every</ins> non-negative integer <code>i &lt; (last - first)</code> the following 
assignment takes place: <code>*(result + (last - first) - i) = *(first + i)</code>.
</p></blockquote></blockquote>
</li>

<li>
<p>Change 26.8.5 <a href="https://wg21.link/alg.partitions">[alg.partitions]</a> p5 and p9 as indicated:</p>

<blockquote><pre>
template&lt;class ForwardIterator, class Predicate&gt;
ForwardIterator
partition(ForwardIterator first,
          ForwardIterator last, Predicate pred);
</pre><blockquote><p>
[&hellip;]
<p/>
-5- <i>Returns</i>: An iterator <code>i</code> such that for <del>any</del><ins>every</ins> iterator <code>j</code> 
in the range <code>[first,i) pred(*j) != false</code>, and for <del>any</del><ins>every</ins> iterator <code>k</code> 
in the range <code>[i,last), pred(*k) == false</code>.
</p></blockquote></blockquote>
<p>
[&hellip;]
</p>
<blockquote><pre>
template&lt;class BidirectionalIterator, class Predicate&gt;
BidirectionalIterator
stable_partition(BidirectionalIterator first,
                 BidirectionalIterator last, Predicate pred);
</pre><blockquote><p>
[&hellip;]
<p/>
-9- <i>Returns</i>: An iterator <code>i</code> such that for <del>any</del><ins>every</ins> iterator <code>j</code> 
in the range <code>[first,i), pred(*j) != false</code>, and for <del>any</del><ins>every</ins> iterator <code>k</code> 
in the range <code>[i,last), pred(*k) == false</code>. The relative order of the elements in both groups is preserved.
</p></blockquote></blockquote>
</li>

<li>
<p>Change 26.8 <a href="https://wg21.link/alg.sorting">[alg.sorting]</a> p5 as indicated:</p>

<blockquote><p>
-5- A sequence is sorted with respect to a comparator <code>comp</code> if for <del>any</del><ins>every</ins> iterator 
<code>i</code> pointing to the sequence and <del>any</del><ins>every</ins> non-negative integer <code>n</code> such that 
<code>i + n</code> is a valid iterator pointing to an element of the sequence, <code>comp(*(i + n), *i) == false</code>.
</p></blockquote>
</li>

<li>
<p>Change 26.8.3 <a href="https://wg21.link/alg.nth.element">[alg.nth.element]</a> p1 as indicated:</p>

<blockquote><pre>
template&lt;class RandomAccessIterator&gt;
void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
                 RandomAccessIterator last);
template&lt;class RandomAccessIterator, class Compare&gt;
void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
                 RandomAccessIterator last, Compare comp);
</pre><blockquote><p>
-1- After <code>nth_element</code> the element in the position pointed to by <code>nth</code> is the element that would 
be in that position if the whole range were sorted. Also for <del>any</del><ins>every</ins> iterator <code>i</code> 
in the range <code>[first,nth)</code> and <del>any</del><ins>every</ins> iterator <code>j</code> in the range 
<code>[nth,last)</code> it holds that: <code>!(*i &gt; *j)</code> or <code>comp(*j, *i) == false</code>. 
</p></blockquote></blockquote>
</li>

<li>
<p>Change 26.8.4.2 <a href="https://wg21.link/lower.bound">[lower.bound]</a> p2 as indicated:</p>

<blockquote><pre>
template&lt;lass ForwardIterator, class T&gt;
ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last,
            const T&amp; value);
template&lt;class ForwardIterator, class T, class Compare&gt;
ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last,
            const T&amp; value, Compare comp);
</pre><blockquote><p>
[&hellip;]
<p/>
-2- <i>Returns</i>: The furthermost iterator <code>i</code> in the range <code>[first,last]</code> such that for 
<del>any</del><ins>every</ins> iterator <code>j</code> in the range <code>[first,i)</code> the following corresponding 
conditions hold: <code>*j &lt; value</code> or <code>comp(*j, value) != false</code>.
</p></blockquote></blockquote>
</li>

<li>
<p>Change 26.8.4.3 <a href="https://wg21.link/upper.bound">[upper.bound]</a> p2 as indicated:</p>

<blockquote><pre>
template&lt;lass ForwardIterator, class T&gt;
ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last,
            const T&amp; value);
template&lt;class ForwardIterator, class T, class Compare&gt;
ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last,
            const T&amp; value, Compare comp);
</pre><blockquote><p>
[&hellip;]
<p/>
-2- <i>Returns</i>: The furthermost iterator <code>i</code> in the range <code>[first,last]</code> such that for 
<del>any</del><ins>every</ins> iterator <code>j</code> in the range <code>[first,i)</code> the following corresponding 
conditions hold: <code>!(value &lt; *j)</code> or <code>comp(value, *j) == false</code>.
</p></blockquote></blockquote>
</li>

<li>
<p>Change 26.8.9 <a href="https://wg21.link/alg.min.max">[alg.min.max]</a> p21 and p23 as indicated:</p>

<blockquote><pre>
template&lt;class ForwardIterator&gt;
ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
template&lt;class ForwardIterator, class Compare&gt;
ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
                            Compare comp);
</pre><blockquote><p>
-21- <i>Returns</i>: The first iterator <code>i</code> in the range <code>[first,last)</code> such that for 
<del>any</del><ins>every</ins> iterator <code>j</code> in the range <code>[first,last)</code> the following 
corresponding conditions hold: <code>!(*j &lt; *i)</code> or <code>comp(*j, *i) == false</code>. Returns 
<code>last</code> if <code>first == last</code>.
</p></blockquote></blockquote>
<p>
[&hellip;]
</p>
<blockquote><pre>
template&lt;class ForwardIterator&gt;
ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
template&lt;class ForwardIterator, class Compare&gt;
ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
                            Compare comp);
</pre><blockquote><p>
-23- <i>Returns</i>: The first iterator <code>i</code> in the range <code>[first,last)</code> such that for 
<del>any</del><ins>every</ins> iterator <code>j</code> in the range <code>[first,last)</code> the following 
corresponding conditions hold: <code>!(*i &lt; *j)</code> or <code>comp(*i, *j) == false</code>. Returns 
<code>last</code> if <code>first == last</code>.
</p></blockquote></blockquote>
</li>

</ol>






</body>
</html>
