title: Narrowing conversion differences
body: <p>With both g++ and clang it's ok to compile</p>
  
  <pre><code>std::vector&lt;int&gt; xs{1, 2, 3u};
  </code></pre>
  
  <p>but it's not ok to compile</p>
  
  <pre><code>std::vector&lt;int&gt; xs{1, 2, 3.0};
  </code></pre>
  
  <p>What is the rationale behind this apparently bizarre choice?</p>
  
  <p>If we consider the <strong>type</strong> of the last value both <code>unsigned</code> and <code>double</code> cannot be converted safely to an <code>int</code>, and if we consider instead <strong>the specific literal values</strong> both <code>3u</code> and <code>3.0</code> can instead be converted safely.</p>
  
  <p>Why the distinction then?</p>
  
  <p>The formal specification says that the conversion is allowed from ints or enums to a different it if the value can be represented and even allows conversions from literals that lose data (for example <code>double</code> to <code>float</code>). Funnily enough this leads to:</p>
  
  <pre><code> std::vector&lt;float&gt; x{1073741824};  // ok, value can be represented
   std::vector&lt;float&gt; y{1073741823};  // not ok, narrowing
   std::vector&lt;float&gt; z{1073741823.}; // ok (even if loses precision!)
   std::vector&lt;int&gt; w{3.0};           // not ok, just because
  </code></pre>