<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 915: minmax with initializer_list should return
pair of T, not pair of const T&amp;</title>
<meta property="og:title" content="Issue 915: minmax with initializer_list should return
pair of T, not pair of const T&amp;">
<meta property="og:description" content="C++ library issue. Status: NAD Editorial">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue915.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_Editorial">NAD Editorial</a> status.</em></p>
<h3 id="915"><a href="lwg-closed.html#915">915</a>. <code>minmax</code> with <code>initializer_list</code> should return
<code>pair</code> of <code>T</code>, not <code>pair</code> of <code>const T&amp;</code></h3>
<p><b>Section:</b> 26.8.9 <a href="https://wg21.link/alg.min.max">[alg.min.max]</a> <b>Status:</b> <a href="lwg-active.html#NAD_Editorial">NAD Editorial</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2008-10-04 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#alg.min.max">active issues</a> in [alg.min.max].</p>
<p><b>View all other</b> <a href="lwg-index.html#alg.min.max">issues</a> in [alg.min.max].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Editorial">NAD Editorial</a> status.</p>
<p><b>Discussion:</b></p>
<p>
It seems that the proposed changes for
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2772.pdf">N2772</a>
were not clear enough in
this point:
</p>

<blockquote><p>
26.8.9 <a href="https://wg21.link/alg.min.max">[alg.min.max]</a>, before p.23 + p.24 + before p. 27 + p. 28 say that the return
type of the <code>minmax</code> overloads with an <code>initializer_list</code> is
<code>pair&lt;const T&amp;, const T&amp;&gt;</code>,
which is inconsistent with the decision for the other <code>min/max</code> overloads which take
a <code>initializer_list</code> as argument and return a <code>T</code>, not a <code>const T&amp;</code>.
Doing otherwise for <code>minmax</code> would easily lead to unexpected life-time
problems by using <code>minmax</code> instead of <code>min</code> and <code>max</code> separately.
</p></blockquote>

<p><i>[
Batavia (2009-05):
]</i></p>

<blockquote><p>
We agree with the proposed resolution.
Move to Tentatively Ready.
</p></blockquote>

<p><i>[
2009-07 Frankfurt
]</i></p>


<blockquote><p>
Moved from Tentatively Ready to Open only because the wording needs to be
tweaked for concepts removal.
</p></blockquote>

<p><i>[
2009-08-18 Daniel adds:
]</i></p>


<blockquote><p>
Recommend NAD since the proposed changes have already been performed
as part of editorial work of
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2914.pdf">N2914</a>.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Can't find <code>initializer_list</code> form of <code>minmax</code> anymore, only variadic
version. Seems like we had an editing clash with concepts. Leave Open,
at least until editorial issues resolved. Bring this to Editor's attention.
</p></blockquote>

<p><i>[
2010 Pittsburgh:  Pete to reapply
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2772.pdf">N2772</a>.
]</i></p>




<p><b>Rationale:</b></p><p>
Solved by reapplying
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2772.pdf">N2772</a>.
</p>

<p id="res-915"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
In 26 <a href="https://wg21.link/algorithms">[algorithms]</a>/2, header <code>&lt;algorithm&gt;</code> synopsis change as indicated:
</p>

<blockquote><pre>
template&lt;<del>class</del><ins>LessThanComparable</ins> T&gt;
<ins>requires CopyConstructible&lt;T&gt;</ins>
pair&lt;<del>const </del>T<del>&amp;</del>, <del>const </del>T<del>&amp;</del>&gt;
minmax(initializer_list&lt;T&gt; t);

template&lt;class T, <del>class</del><ins>StrictWeakOrder&lt;auto, T&gt;</ins> Compare&gt;
<ins>requires CopyConstructible&lt;T&gt;</ins>
pair&lt;<del>const </del>T<del>&amp;</del>, <del>const </del>T<del>&amp;</del>&gt;
minmax(initializer_list&lt;T&gt; t, Compare comp);
</pre></blockquote>
</li>
<li>
<p>
In 26.8.9 <a href="https://wg21.link/alg.min.max">[alg.min.max]</a> change as indicated (Begin: Just before p.20):
</p>
<blockquote><pre>
template&lt;<del>class</del><ins>LessThanComparable</ins> T&gt;
  <ins>requires CopyConstructible&lt;T&gt;</ins>
  pair&lt;<del>const </del>T<del>&amp;</del>, <del>const </del>T<del>&amp;</del>&gt;
  minmax(initializer_list&lt;T&gt; t);
</pre>
<blockquote>
<p>
<del>-20- <i>Requires:</i> <code>T</code> is <code>LessThanComparable</code> and
<code>CopyConstructible</code>.</del>
</p>
<p>
-21- <i>Returns:</i> <code>pair&lt;<del>const </del>T<del>&amp;</del>, <del>const
</del>T<del>&amp;</del>&gt;(x, y)</code> where <code>x</code> is the
smallest value and <code>y</code> the largest value in the <code>initializer_list</code>.
</p>
</blockquote>

<p>[..]</p>
<pre>
template&lt;class T, <del>class</del><ins>StrictWeakOrder&lt;auto, T&gt;</ins> Compare&gt;
  <ins>requires CopyConstructible&lt;T&gt;</ins>
  pair&lt;<del>const </del>T<del>&amp;</del>, <del>const </del>T<del>&amp;</del>&gt;
  minmax(initializer_list&lt;T&gt; t, Compare comp);
</pre>

<blockquote>
<p>
<del>-24- <i>Requires:</i> type <code>T</code> is <code>LessThanComparable</code> and <code>CopyConstructible</code>.</del>
</p>
<p>
-25- <i>Returns:</i> <code>pair&lt;<del>const </del>T<del>&amp;</del>, <del>const
</del>T<del>&amp;</del>&gt;(x, y)</code> where <code>x</code> is the
smallest value and <code>y</code> largest value in the <code>initializer_list</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>






</body>
</html>
