Boost C++ Libraries: Ticket #12081: the minmax creates dangling references too easily https://svn.boost.org/trac10/ticket/12081 <p> First. minmax's example codes has created dangling references. </p> <pre class="wiki">boost::tuple&lt;int const&amp;, int const&amp;&gt; result1 = boost::minmax(1, 0); //actual code boost::tuple&lt;int, int&gt; result1 = boost::minmax(1, 0); //expected code </pre><p> <a href="http://www.boost.org/doc/libs/1_60_0/libs/algorithm/minmax/index.html">http://www.boost.org/doc/libs/1_60_0/libs/algorithm/minmax/index.html</a> <br /> <a href="http://www.boost.org/doc/libs/1_60_0/libs/algorithm/minmax/example/minmax_ex.cpp">http://www.boost.org/doc/libs/1_60_0/libs/algorithm/minmax/example/minmax_ex.cpp</a> </p> <p> <br /> </p> <p> Second. The design of minmax is unsuitable for that of C++11 era. Consider the following. </p> <pre class="wiki">auto tp = minmax(1,2); tp.get&lt;0&gt;(); // Undefined behavior </pre><p> This code looks like fairy normal, but it causes undefined behavior. Since the minmax returns tuple&lt;T const&amp;, T const&amp;&gt;, the 'auto tp' has dangling references. <br /> </p> <p> I think we should change the return type from tuple&lt;T const&amp;, T const&amp;&gt; to tuple&lt;T,T&gt;. </p> <p> See also: <a class="ext-link" href="https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/HLiJJBRNYSw"><span class="icon">​</span>https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/HLiJJBRNYSw</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12081 Trac 1.4.3 Marshall Clow Wed, 21 Feb 2018 22:18:06 GMT <link>https://svn.boost.org/trac10/ticket/12081#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12081#comment:1</guid> <description> <p> This is the same interface that <code>std::min</code> has. </p> <blockquote> <p> int const &amp;x = std::min(0,1); </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 21 Feb 2018 22:20:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12081#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12081#comment:2</guid> <description> <blockquote class="citation"> <p> I think we should change the return type from tuple&lt;T const&amp;, T const&amp;&gt; to tuple&lt;T,T&gt;. </p> </blockquote> <p> That would add the requirement that <code>T</code> be copyable. </p> </description> <category>Ticket</category> </item> </channel> </rss>