<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1000: adjacent_find is over-constrained</title>
<meta property="og:title" content="Issue 1000: adjacent_find is over-constrained">
<meta property="og:description" content="C++ library issue. Status: NAD Concepts">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1000.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#NAD_Concepts">NAD Concepts</a> status.</em></p>
<h3 id="1000"><a href="lwg-closed.html#1000">1000</a>. adjacent_find is over-constrained</h3>
<p><b>Section:</b> 26.6.10 <a href="https://wg21.link/alg.adjacent.find">[alg.adjacent.find]</a> <b>Status:</b> <a href="lwg-active.html#NAD_Concepts">NAD Concepts</a>
 <b>Submitter:</b> Chris Jefferson <b>Opened:</b> 2009-03-09 <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#alg.adjacent.find">issues</a> in [alg.adjacent.find].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Concepts">NAD Concepts</a> status.</p>
<p><b>Discussion:</b></p>
<p>
<b>Addresses UK 296</b>
</p>

<p>
<code>adjacent_find</code> in C++03 allows an arbitrary predicate, but in C++0x
<code>EqualityComparable/EquivalenceRelation</code> is required. This forbids a
number of use cases, including:
</p>
<blockquote>
<table>
<tr>
<td valign="top">
<code>adjacent_find(begin,&nbsp;end,&nbsp;less&lt;double&gt;)</code>
</td>
<td>
Find the first
place where a range is not ordered in decreasing order - in use to check
for sorted ranges.
</td>
</tr>
<tr>
<td valign="top">
<code>adjacent_find(begin,&nbsp;end,&nbsp;DistanceBiggerThan(6)&nbsp;)&nbsp;)</code>
</td>
<td>
Find the first
place in a range where values differ by more than a given value - in use
to check an algorithm which produces points in space does not generate
points too far apart.
</td>
</tr>
</table>
</blockquote>

<p>
A number of books use predicate which are not equivalence relations in
examples, including "Thinking in C++" and "C++ Primer".
</p>

<p>
Adding the requirement that the predicate is an <code>EquivalenceRelation</code>
does not appear to open up any possibility for a more optimised algorithm.
</p>



<p id="res-1000"><b>Proposed resolution:</b></p>
<p>
Change the definition of adjacent_find in the synopsis of 26 <a href="https://wg21.link/algorithms">[algorithms]</a>
and 26.6.10 <a href="https://wg21.link/alg.adjacent.find">[alg.adjacent.find]</a> to:
</p>

<blockquote><pre>
template&lt;ForwardIterator Iter&gt; 
  requires <del>EqualityComparable</del><ins>HasEqualTo</ins>&lt;Iter::value_type<ins>, Iter::value_type</ins>&gt;
  Iter adjacent_find(Iter first, Iter last);

template&lt;ForwardIterator Iter, <del>EquivalenceRelation</del><ins>Predicate</ins>&lt;auto, Iter::value_type<ins>, Iter::value_type</ins>&gt; Pred&gt; 
  requires CopyConstructible&lt;Pred&gt; 
  Iter adjacent_find(Iter first, Iter last, Pred pred);
</pre></blockquote>





</body>
</html>
