title: Check whether two elements have a common element in C++
body: <p>I want the function to return true when there is any element matching between two vectors,</p>
  
  <p><code>Note : My vectors are not sorted</code>
  Following is my source code,</p>
  
  <pre><code>bool CheckCommon( std::vector&lt; long &gt; &amp;inVectorA, std::vector&lt; long &gt; &amp;inVectorB )
  {
      std::vector&lt; long &gt; *lower, *higher;
  
      size_t sizeL = 0, sizeH = 0;
  
      if( inVectorA.size() &gt; inVectorB.size() )
      {
          lower = &amp;inVectorA;
          sizeL = inVectorA.size();
          higher = &amp;inVectorB;
          sizeH = inVectorB.size();
      }
      else
      {
          lower = &amp;inVectorB;
          sizeL = inVectorB.size();
          higher = &amp;inVectorA;
          sizeH = inVectorA.size();
      }
  
      size_t indexL = 0, indexH = 0;
  
      for( ; indexH &lt; sizeH; indexH++ )
      {
          bool exists = std::binary_search( lower-&gt;begin(), lower-&gt;end(), higher-&gt;at(indexH) );
  
          if( exists == true )
              return true;
          else
              continue;
      }
      return false;
  }
  </code></pre>
  
  <p>This is working fine when the size of vector B is less than the size of vector A , but returning false even there is match when size of vector B is greater than size of vector A .</p>