title: val != std::numeric_limits<double>::infinity() or !isinf(val) or isfinite(val)
body: <p>This is likely <a href="https://en.wiktionary.org/wiki/bikeshedding" rel="nofollow noreferrer">bike-shedding</a>, but maybe there is something interesting I'm missing...</p>
  
  <p>If a class initializes a member <code>val</code> to <code>std::numeric_limits&lt;double&gt;::infinity()</code> and later wants to check if val has been changed to something valid (+/- inf are not valid here), what are the tradeoffs of these 3 approaches and did I miss any other interesting ways to solve this. (removed const for readability in the examples.)</p>
  
  <pre><code>bool IsInit() { return MinX != std::numeric_limits&lt;double&gt;::infinity(); }  // a
  
  bool IsInit() { return !std::isinf(MinX); }  // b
  
  bool IsInit() { return std::isfinite(MinX); }  // c
  </code></pre>
  
  <p>For now the code is C++03, but how would the options change with C++11, C++14 and C++17.  e.g. with C++17, this code could be just <code>std::optional&lt;double&gt; val</code>.  Or would quiet NaN be a safer bet just incase +/-inf became valid in the future?</p>
  
  <p>This came up when I was reading this patch to this code:</p>
  
  <ul>
  <li><a href="https://github.com/OSGeo/gdal/commit/30194c640f403008625ff0c8be7aca155ac7ebe1" rel="nofollow noreferrer">https://github.com/OSGeo/gdal/commit/30194c640f403008625ff0c8be7aca155ac7ebe1</a></li>
  <li><a href="https://trac.osgeo.org/gdal/browser/trunk/gdal/ogr/ogr_core.h?rev=37821#L76" rel="nofollow noreferrer">https://trac.osgeo.org/gdal/browser/trunk/gdal/ogr/ogr_core.h?rev=37821#L76</a></li>
  </ul>
  
  <p>For easy reference:</p>
  
  <ul>
  <li><a href="http://en.cppreference.com/w/cpp/types/numeric_limits/infinity" rel="nofollow noreferrer">std::numeric_limits::infinity()</a></li>
  <li><a href="http://en.cppreference.com/w/cpp/numeric/math/isinf" rel="nofollow noreferrer">std::isinf</a></li>
  <li><a href="http://en.cppreference.com/w/cpp/numeric/math/isfinite" rel="nofollow noreferrer">std::isfinite</a></li>
  <li><a href="http://en.cppreference.com/w/cpp/types/numeric_limits/quiet_NaN" rel="nofollow noreferrer">std::numeric_limits::quiet_NaN</a></li>
  <li><a href="http://en.cppreference.com/w/cpp/utility/optional" rel="nofollow noreferrer">std::optional</a></li>
  </ul>
  
  <p>Sort of related:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/28548637/in-c-is-it-safe-to-use-stdnumeric-limitsdoublemax-as-a-special-flag">is it safe to use std::numeric_limits::max() as a special “flag”?</a></li>
  </ul>