title: Vector iterator comparison
body: <p>I have a problem while comparing the values in two vectors.</p>
  
  <p>Following is the sample code of my program:</p>
  
  <pre><code>  template &lt;typename T&gt; bool CompareVectors(std::vector&lt;T&gt; vector1, std::vector&lt;T&gt; vector2)
    {
      std::sort(vector1.begin(),vector1.end());
      std::sort(vector2.begin(),vector2.end());
      if (vector1.size() != vector2.size())
        return false;
      else
      {
        bool found = false;
        std::vector&lt;T&gt;::iterator it;
        std::vector&lt;T&gt;::iterator it2;
        for (it = vector1.begin();it != vector1.end(); it++)
        {      
          for(it2 = vector2.begin(); it2 != vector2.end(); it2++)
          {
            if(it == it2) // here i have to check the values in the itearators are equal.
            {
              found = true;
              break;
            }
          }
          if(!found)
            return false;
          else
            found = false;
        }
        return true;  
      }
      };
  </code></pre>
  
  <p>In this sample code I have to compare the two vectors. For that I have sorted the two vectors using <code>std::sort()</code>. Since the data type in the vector is a template (I am using a class object in the vector), the <code>std::sort()</code> is not working properly. Ie, sometimes the two vectors give different order of elements after sorting.</p>
  
  <p>So I am not able to use the <code>std::equal()</code> function also.</p>
  
  <p>For an alternative solution, I have used two iterators for the twi vectors.</p>
  
  <p>And iterating one vector and searches that element in the other vector. For this the iterator comparison is cannot be usable.</p>