title: Avoid signed by unsigned integer division
body: <p>I ran into this problem when I was doing the following code:</p>
  
  <pre><code>int average = std::accumulate(vi.begin(), vi.end(), 0) / vi.size();
  </code></pre>
  
  <p>Without an <code>int</code> cast on <code>vi.size()</code> the output is garbage, because <code>size()</code> returns an unsigned integer.</p>
  
  <p>I never would've figured this out if I hadn't googled a reference for vector. Is there a way of avoiding this trap? With <code>-Wall</code> and <code>-pedantic</code>, gcc doesn't seem to give any warnings about this kind of division.</p>