title: GCC: comparison is always true due to limited range of data type -- in Template Parameter?
body: <p>I want to write a template that returns me the smallest signed integer type that can represent a given number. This is my solution:</p>
  
  <pre><code>/**
   * Helper for IntTypeThatFits.
   * Template parameters indicate whether the given number fits into 8, 16 or 32
   * bits. If neither of them is true, it is assumed that it fits 64 bits.
   */
  template &lt;bool fits8, bool fits16, bool fits32&gt;
  struct IntTypeThatFitsHelper { };
  
  // specializations for picking the right type
  // these are all valid combinations of the flags
  template&lt;&gt; struct IntTypeThatFitsHelper&lt;true, true, true&gt; { typedef int8_t Result; };
  template&lt;&gt; struct IntTypeThatFitsHelper&lt;false, true, true&gt; { typedef int16_t Result; };
  template&lt;&gt; struct IntTypeThatFitsHelper&lt;false, false, true&gt; { typedef int32_t Result; };
  template&lt;&gt; struct IntTypeThatFitsHelper&lt;false, false, false&gt; { typedef int64_t Result; };
  
  /// Finds the smallest integer type that can represent the given number.
  template &lt;int64_t n&gt;
  struct IntTypeThatFits
  {
      typedef typename IntTypeThatFitsHelper&lt;
          (n &lt;= numeric_limits&lt;int8_t&gt;::max()) &amp;&amp; (n &gt;= numeric_limits&lt;int8_t&gt;::min()), 
          (n &lt;= numeric_limits&lt;int16_t&gt;::max()) &amp;&amp; (n &gt;= numeric_limits&lt;int16_t&gt;::min()), 
          (n &lt;= numeric_limits&lt;int32_t&gt;::max()) &amp;&amp; (n &gt;= numeric_limits&lt;int32_t&gt;::min())
      &gt;::Result Result;
  };
  </code></pre>
  
  <p>However, GCC does not accept this code. I get an error "comparison is always true due to limited range of data type [-Werror=type-limits]". Why does that happen? n is a signed 64bit integer, and all of the comparisons may be true or false for different values of n, or am I overlooking something?</p>
  
  <p>I will be glad for any help.</p>
  
  <p>Edit: I should mention that I am using C++11.</p>