mixed_relational_comparisons.html 5.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Mixed relational comparisons</title>
  5. <link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../../../index.html" title="Boost.Optional">
  8. <link rel="up" href="../gotchas.html" title="Gotchas">
  9. <link rel="prev" href="moved_from__optional_.html" title="Moved-from optional">
  10. <link rel="next" href="false_positive_with__wmaybe_uninitialized.html" title="False positive with -Wmaybe-uninitialized">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr>
  14. <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="moved_from__optional_.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../gotchas.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="false_positive_with__wmaybe_uninitialized.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h4 class="title">
  27. <a name="boost_optional.tutorial.gotchas.mixed_relational_comparisons"></a><a class="link" href="mixed_relational_comparisons.html" title="Mixed relational comparisons">Mixed
  28. relational comparisons</a>
  29. </h4></div></div></div>
  30. <p>
  31. Because <code class="computeroutput"><span class="identifier">T</span></code> is convertible
  32. to <code class="computeroutput"><span class="identifier">optional</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
  33. and because <code class="computeroutput"><span class="identifier">opiotnal</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
  34. is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a> when <code class="computeroutput"><span class="identifier">T</span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>, you can sometimes
  35. get an unexpected runtime result where you would rather expect a compiler
  36. error:
  37. </p>
  38. <pre class="programlisting"><span class="identifier">optional</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">Flight_plan</span><span class="special">::</span><span class="identifier">weight</span><span class="special">();</span> <span class="comment">// sometimes no weight can be returned</span>
  39. <span class="keyword">bool</span> <span class="identifier">is_aircraft_too_heavy</span><span class="special">(</span><span class="identifier">Flight_plan</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">)</span>
  40. <span class="special">{</span>
  41. <span class="keyword">return</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">weight</span><span class="special">()</span> <span class="special">&gt;</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">aircraft</span><span class="special">().</span><span class="identifier">max_weight</span><span class="special">();</span> <span class="comment">// compiles!</span>
  42. <span class="special">}</span> <span class="comment">// returns false when the optional contains no value </span>
  43. </pre>
  44. </div>
  45. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  46. <td align="left"></td>
  47. <td align="right"><div class="copyright-footer">Copyright &#169; 2003-2007 Fernando Luis Cacciola Carballal<br>Copyright &#169; 2014-2018 Andrzej Krzemie&#324;ski<p>
  48. Distributed under the Boost Software License, Version 1.0. (See accompanying
  49. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  50. </p>
  51. </div></td>
  52. </tr></table>
  53. <hr>
  54. <div class="spirit-nav">
  55. <a accesskey="p" href="moved_from__optional_.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../gotchas.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="false_positive_with__wmaybe_uninitialized.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
  56. </div>
  57. </body>
  58. </html>