title: static assert for const variables?
body: <p>Static asserts are very convenient for checking things in compile time. A simple static assert idiom looks like this:</p>
  
  <pre><code>template&lt;bool&gt; struct StaticAssert;
  template&lt;&gt; struct StaticAssert&lt;true&gt; {};
  
  #define STATIC_ASSERT(condition) do { StaticAssert&lt;(condition)&gt;(); } while(0)
  </code></pre>
  
  <p>This is good for stuff like</p>
  
  <pre><code>STATIC_ASSERT(sizeof(float) == 4)
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>#define THIS_LIMIT (1000)
  ...
  STATIC_ASSERT(THIS_LIMIT &gt; OTHER_LIMIT);
  </code></pre>
  
  <p>But using <code>#define</code> is not the "C++" way of defining constants. C++ would have you use an anonymous namespace:</p>
  
  <pre><code>namespace {
      const int THIS_LIMIT = 1000;
  }
  </code></pre>
  
  <p>or even:</p>
  
  <pre><code>static const int THIS_LIMIT = 1000;
  </code></pre>
  
  <p>The trouble with this is that with a <code>const int</code> you can't use <code>STATIC_ASSERT()</code> and you must resort to a run-time check which is silly.</p>
  
  <p>Is there a way to properly solve this in current C++?<br>
  I think I've read C++0x has some facility to do this...</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok so this </p>
  
  <pre><code>static const int THIS_LIMIT = 1000;
  ...
  STATIC_ASSERT(THIS_LIMIT &gt; 0);
  </code></pre>
  
  <p>compiles fine<br>
  But this:</p>
  
  <pre><code>static const float THIS_LIMIT = 1000.0f;
  ...
  STATIC_ASSERT(THIS_LIMIT &gt; 0.0f);
  </code></pre>
  
  <p>does not.<br>
  (in Visual Studio 2008)</p>
  
  <p>How come?</p>