title: Vector sum in C++ design strategy
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3221812/sum-of-elements-in-a-stdvector">sum of elements in a <code>std::vector</code></a>  </p>
  </blockquote>
  
  
  
  <p>I want to sum the items of a std::vector</p>
  
  <p>For example</p>
  
  <pre><code> std::vector&lt;int &gt; MYvec;
   /*some push backs*/
  
   int x=sum(MYVec); //it should give sum of all the items in the vector
  </code></pre>
  
  <p>How to write <code>sum</code> function?</p>
  
  <p>I have tried this</p>
  
  <pre><code> int sum(const std::vector&lt;int&gt; &amp;Vec)
   {
      int result=0;
      for (int i=0;i&lt;Vec.size();++i)
        result+=Vec[i];
      return result;
   }
  </code></pre>
  
  <p>However I don't like my approach</p>