<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2688: clamp misses preconditions and has extraneous condition on result</title>
<meta property="og:title" content="Issue 2688: clamp misses preconditions and has extraneous condition on result">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2688.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++17">C++17</a> status.</em></p>
<h3 id="2688"><a href="lwg-defects.html#2688">2688</a>. <code>clamp</code> misses preconditions and has extraneous condition on result</h3>
<p><b>Section:</b> 26.8.10 <a href="https://wg21.link/alg.clamp">[alg.clamp]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Martin Moene <b>Opened:</b> 2016-03-23 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>0
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In Jacksonville (2016), <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0025r0.html">P0025R0</a> was 
voted in instead of the intended <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0025r1.html">P0025R1</a>. 
This report contains the necessary mending along with two other improvements.
<p/>
This report:
</p>
<ul>
<li><p>adds the precondition that misses from P0025R0 but is in P0025R1,</p></li>
<li><p>corrects the returns: specification that contains an extraneous condition,</p></li>
<li><p>replaces the now superfluous remark with a note on usage of clamp with <code>float</code> or <code>double</code>.</p></li>
</ul>
<p>
Thanks to Carlo Assink and David Gaarenstroom for making us aware of the extraneous condition in the returns: 
specification and for suggesting the fix and to Jeffrey Yasskin for suggesting to add a note like p3.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<ol>
<li><p>Edit 26.8.10 <a href="https://wg21.link/alg.clamp">[alg.clamp]</a> as indicated:</p>

<blockquote><pre>
template&lt;class T&gt;
  constexpr const T&amp; clamp(const T&amp; v, const T&amp; lo, const T&amp; hi);
template&lt;class T, class Compare&gt;
  constexpr const T&amp; clamp(const T&amp; v, const T&amp; lo, const T&amp; hi, Compare comp);
</pre>
<blockquote>
<p>
-1- <i>Requires</i>: <ins>The value of <code>lo</code> shall be no greater than <code>hi</code>.</ins> For the first form, 
type <code>T</code> shall be <code>LessThanComparable</code> (Table 18).
<p/>
-2- <i>Returns</i>: <ins><code>lo</code> if <code>v</code> is less than <code>lo</code>, <code>hi</code> if <code>hi</code> is less than 
<code>v</code>, otherwise <code>v</code></ins><del>The larger value of <code>v</code> and <code>lo</code> if <code>v</code> is smaller than 
<code>hi</code>, otherwise the smaller value of <code>v</code> and <code>hi</code></del>.
<p/>
-3- <i><ins>Note</ins><del>Remarks</del></i>: <ins>If NaN is avoided, <code>T</code> can be <code>float</code> or 
<code>double</code></ins><del>Returns the first argument when it is equivalent to one of the boundary arguments</del>.
<p/>
-4- <i>Complexity</i>: At most two comparisons.
</p>
</blockquote>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2016-05 Issues Telecon]</i></p>

<p>
Reworded p3 slightly.
</p>


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

<ol>
<li><p>Edit 26.8.10 <a href="https://wg21.link/alg.clamp">[alg.clamp]</a> as indicated:</p>

<blockquote><pre>
template&lt;class T&gt;
  constexpr const T&amp; clamp(const T&amp; v, const T&amp; lo, const T&amp; hi);
template&lt;class T, class Compare&gt;
  constexpr const T&amp; clamp(const T&amp; v, const T&amp; lo, const T&amp; hi, Compare comp);
</pre>
<blockquote>
<p>
-1- <i>Requires</i>: <ins>The value of <code>lo</code> shall be no greater than <code>hi</code>.</ins> For the first form, 
type <code>T</code> shall be <code>LessThanComparable</code> (Table 18).
<p/>
-2- <i>Returns</i>: <ins><code>lo</code> if <code>v</code> is less than <code>lo</code>, <code>hi</code> if <code>hi</code> is less than 
<code>v</code>, otherwise <code>v</code></ins><del>The larger value of <code>v</code> and <code>lo</code> if <code>v</code> is smaller than 
<code>hi</code>, otherwise the smaller value of <code>v</code> and <code>hi</code></del>.
<p/>
-3- <i><ins>Note</ins><del>Remarks</del></i>: <ins>If NaN is avoided, <code>T</code> can be a floating point type</ins>
<del>Returns the first argument when it is equivalent to one of the boundary arguments</del>.
<p/>
-4- <i>Complexity</i>: At most two comparisons.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
