title: Template function for container and type to compare vector of pointers
body: <p>I want to compare 2 containers (vectors or sets) of pointers. I am trying to have a function that is also independent of the type.</p>
  
  <p>First I tried the following. But the problem is that it is always returning 0 even tho both containers have objects with same content.</p>
  
  <pre><code>  template&lt;typename Container &gt;
      bool isEqual(const Container &amp;lhs,const Container &amp;rhs ) {
          bool ok = equal(begin(lhs), end(lhs), begin(rhs));
  
          return ok;
      }
  </code></pre>
  
  <p>Then I tried to use the following function:</p>
  
  <pre><code> template&lt;typename T , typename Container &gt;
      bool isEqual(const Container &amp;lhs,const Container &amp;rhs ) {
          bool ok = equal(begin(lhs), end(lhs), begin(rhs),
                      [](const T* lhs, const T* rhs){ return *lhs == * rhs; });
  
          return ok;
      }
  </code></pre>
  
  <p>but the problem is that it is producing the following errors and I don't understand why. </p>
  
  <pre><code> In function 'int main()':
  31:31: error: no matching function for call to 'isEqual(std::vector&lt;Point*&gt;&amp;, std::vector&lt;Point*&gt;&amp;)'
  31:31: note: candidate is:
  19:6: note: template&lt;class T, class Container&gt; bool isEqual(const Container&amp;, const Container&amp;)
  19:6: note:   template argument deduction/substitution failed:
  31:31: note:   couldn't deduce template parameter 'T'
  36:31: error: no matching function for call to 'isEqual(std::set&lt;Point*&gt;&amp;, std::set&lt;Point*&gt;&amp;)'
  36:31: note: candidate is:
  19:6: note: template&lt;class T, class Container&gt; bool isEqual(const Container&amp;, const Container&amp;)
  19:6: note:   template argument deduction/substitution failed:
  36:31: note:   couldn't deduce template parameter 'T'
  </code></pre>
  
  <hr>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;set&gt;
  
  using namespace std;
  
  class Point {
      public:
      Point(int x, int y):_x(x),_y(y) {}
      private:
       int _x;
       int _y;
  };
  
  template&lt;typename T , typename Container &gt;
  bool isEqual(const Container &amp;lhs,const Container &amp;rhs ) {
      bool ok = equal(begin(lhs), end(lhs), begin(rhs),
                  [](const T* lhs, const T* rhs){ return *lhs == * rhs; });
  
      return ok;
  }
  
  int main()
  {
      std::vector&lt;Point *&gt; v1 = {new Point(10,10)};
      std::vector&lt;Point *&gt; v2  = {new Point(10,10)};
  
      std::cout &lt;&lt; isEqual(v1,v2) &lt;&lt; std::endl;
  
      std::set&lt;Point *&gt; s1 = {new Point(10,10)};
      std::set&lt;Point *&gt; s2  = {new Point(10,10)};
  
      std::cout &lt;&lt; isEqual(s1,s2) &lt;&lt; std::endl;
  
      return 0;
  } 
  </code></pre>