title: C++ Template Function for Vector of Unique Elements
body: <p>I am trying to create a template function that takes an input vector of type T, by reference, and modifies that vector in such a way that it contains only unique elements:</p>
  
  <p>This is what I have got so far:</p>
  
  <pre><code>template&lt;typename T&gt;
  void uniqueOnly(vector&lt;T&gt;&amp; vec){
    typedef typename std::vector&lt;T&gt;::iterator it;
    it = std::unique(vec.begin(), vec.end());
    vec.resize( std::distance(vec.begin(),it) );
  }
  </code></pre>
  
  <p>However, I am getting a couple of errors when trying to compile, Namely:</p>
  
  <blockquote>
    <p>functions.cpp:52:6: error: expected unqualified-id   it =
    std::unique(vec.begin(), vec.end());</p>
  </blockquote>
  
  <p>And</p>
  
  <blockquote>
    <p>functions.cpp:53:41: error: unexpected type name 'it': expected
    expression   vec.resize( std::distance(vec.begin(),it) );</p>
  </blockquote>
  
  <p>Would someone please be so generous as to decrypt those error messages for me, and point me in the right direction to fix the problem?</p>