<html>
<head>
<title>minmax proposed text</title>
<style>
p {text-align:justify}
li {text-align:justify}
blockquote.note
{
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
}
ins {background-color:#FFFFA0}
del {background-color:#FFFFA0}
</style>
</head>

<body>

<address align=right>
Document number: N1990=06-0060<br>
<br>
<a href="mailto:hinnant@twcny.rr.com">Howard E. Hinnant</a><br>
2006-04-06
</address>
<hr>

<h1 align="center">Proposed Text for minmax (N1840)</h1>

<h2>Explanation</h2>

<p>
The LWG would like to accept N1840 into the C++0X working draft with one chanage:
</p>

<ul>
<li>Remove <tt>reference_wrapper</tt> as it is no longer needed due to CWG issue 106
(references to references).</li>
</ul>

<h2>Proposed Wording</h2>

<p>
In the <b>header &lt;algorithm&gt; synopsis</b>, add:
</p>

<pre>
<i>// 25.3.7, minimum and maximum:</i>
<i>// [ ... min, max, followed by]</i>
    template &lt;class T&gt; 
      pair&lt;const T&amp;, const T&amp;&gt;
        minmax(const T&amp; a, const T&amp; b); 
    template &lt;class T, class Compare&gt;
      pair&lt;const T&amp;, const T&amp;&gt;
        minmax(const T&amp; a, const T&amp; b, Compare comp);
<i>// [ ... min_element, and max_element]</i>
</pre>

<p>
In section 25.3.7, add:
</p>

<blockquote><pre>
template &lt;class T&gt; 
  pair&lt;const T&amp;, const T&amp;&gt;
    minmax(const T&amp; a, const T&amp; b); 
template &lt;class T, class Compare&gt;
  pair&lt;const T&amp;, const T&amp;&gt;
    minmax(const T&amp; a, const T&amp; b, Compare comp);
</pre></blockquote>

<p>
-7- <b>Requires:</b>Type <tt>T</tt> is <tt>LessThanComparable</tt> (20.1.2).
</p>

<p>
-8- <b>Returns:</b> <tt>pair&lt;const T&amp;, const T&amp;&gt;(b, a)</tt> if <tt>b</tt>
is smaller than <tt>a</tt>, and <tt>pair&lt;const T&amp;, const T&amp;&gt;(a, b)</tt> otherwise.
</p>

<p>
-9- <b>Remarks:</b> Returns <tt>pair&lt;const T&amp;, const T&amp;&gt;(a, b)</tt>
if <tt>a</tt> and <tt>b</tt> are equivalent. 
</p>

<p>
-10- <b>Complexity:</b> Exactly one comparison.
</p>

<p>
In the <b>header &lt;algorithm&gt; synopsis</b>, add (and by the way, the comment heading 
25.3.8 is missing in the synopsis even in the 2003 revision):
</p>

<pre>
<i>// 25.3.7, minimum and maximum:</i>
<i>// [... min_element, and max_element, followed by:]</i>
template &lt;class ForwardIterator&gt;
  pair&lt;ForwardIterator, ForwardIterator&gt;
    minmax_element(ForwardIterator first, ForwardIterator last);
template &lt;class ForwardIterator, class Compare&gt;
  pair&lt;ForwardIterator, ForwardIterator&gt;
    minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);

<i>// 25.3.8, lexicographical comparisons:</i>
<i>// [... lexicographical_compare, etc.]</i>
</pre>

<p>
At the end of section 25.3.7, add:
</p>

<blockquote><pre>
template &lt;class ForwardIterator&gt;
  pair&lt;ForwardIterator, ForwardIterator&gt;
    minmax_element(ForwardIterator first, ForwardIterator last);
template &lt;class ForwardIterator, class Compare&gt;
  pair&lt;ForwardIterator, ForwardIterator&gt;
    minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
</pre></blockquote>

<p>
-15- <b>Returns:</b> <tt>std::make_pair(m, M)</tt> where <tt>m</tt> is the
<tt>std::min_element</tt> and <tt>M</tt> the <tt>std::max_element</tt> of
the input range <tt>[first, last)</tt> for the corresponding comparisons.
</p>

<p>
-16- <b>Complexity:</b> At most <tt>max(2*(last-first)-2, 0)</tt> applications of the
corresponding comparisons.
</p>

</body>
</html>
