title: How to solve this error in unordered_set hasher function of custom class objects?
body: <p>I am using unordered map for the first time and that with custom objects. I tried to write the below functions. There are errors that I need help with. </p>
  
  <p>This is the class.</p>
  
  <pre><code>class Node
  {
    public:
      int g= 0, h=0;
      char val;                                                              //Char value in the grid
      pair&lt;int,int&gt; pos,parent;  
      bool par_prsnt = false;                                                //Bool to check if the parent is set
  
  
      Node(pair&lt;int,int&gt;nodePos,char value)
      {
      pos=nodePos;
      val=value;
      }  
  
      int move_cost(Node other)
      {
      if (val=='.')
          return 0;
      else
          return 1;
      }
  
      pair&lt;int,int&gt; get_pos() const
      {
      return pos;
      }
  
      void set_parent(pair&lt;int,int&gt; par)
      {
      parent = par;
      par_prsnt = true;
      }
  
  };
  </code></pre>
  
  <p>Below is the custom functions:</p>
  
  <pre><code>// Custom Hasher for Class Node, to be used for Unordered_set
  struct NodeHasher
  {
    template &lt;typename T, typename U&gt;
    size_t
    const operator()(const Node &amp;obj)
    {
      pair&lt;T,U&gt; position;
      position = obj.get_pos();
      return 3* std::hash&lt;T&gt;()(position.first) + std::hash&lt;U&gt;()(position.second) ;
    }
  };
  
  // Custom Comparator for Class Node, to be used for Unordered_set
  struct NodeComparator
  {
    bool
    const operator()(const Node  &amp;obj1, const  Node  &amp;obj2) const
    {
      if (obj1.get_pos() == obj2.get_pos())
        return true;
      return false;
    }
  };
  </code></pre>
  
  <p>I get the following errors:</p>
  
  <pre><code>Player 1: compilation error
  In file included from /usr/include/c++/7/bits/hashtable.h:35:0,
  from /usr/include/c++/7/unordered_map:47,
  from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:117,
  solution.cc:7:
  /usr/include/c++/7/bits/hashtable_policy.h: In instantiation of ‘struct std::__detail::__is_noexcept_hash’:
  /usr/include/c++/7/type_traits:143:12: required from ‘struct std::__and_,  std::__detail::__is_noexcept_hash &gt;’
  /usr/include/c++/7/type_traits:154:31: required from ‘struct std::__not_, std::__detail::__is_noexcept_hash &gt; &gt;’
  /usr/include/c++/7/bits/unordered_set.h:98:63: required from ‘class std::unordered_set’
  solution.cc:119:51: required from here
  /usr/include/c++/7/bits/hashtable_policy.h:87:34: error: no match for call to ‘(const NodeHasher) (const Node&amp;)’
  noexcept(declval()(declval()))&gt;
  ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
  solution.cc:83:9: note: candidate: template const size_t NodeHasher::operator()(const Node&amp;)
  const operator()(const Node &amp;obj)
  ^~~~~~~~
  solution.cc:83:9: note: template argument deduction/substitution failed:
  In file included from /usr/include/c++/7/bits/hashtable.h:35:0,
  from /usr/include/c++/7/unordered_map:47,
  from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:117,
  solution.cc:7:
  /usr/include/c++/7/bits/hashtable_policy.h:87:34: note: couldn't deduce template parameter ‘T’
  noexcept(declval()(declval()))&gt;
  ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
  In file included from /usr/include/c++/7/bits/move.h:54:0,
  from /usr/include/c++/7/bits/stl_pair.h:59,
  from /usr/include/c++/7/bits/stl_algobase.h:64,
  from /usr/include/c++/7/vector:60,
  solution.cc:3:
  /usr/include/c++/7/type_traits: In instantiation of ‘struct std::__not_, std::__detail::__is_noexcept_hash &gt; &gt;’:
  /usr/include/c++/7/bits/unordered_set.h:98:63: required from ‘class std::unordered_set’
  solution.cc:119:51: required from here
  /usr/include/c++/7/type_traits:154:31: error: ‘value’ is not a member of ‘std::__and_, std::__detail::__is_noexcept_hash &gt;’
  : public __bool_constant
  ^~~~~~~~~~~~~~~~
  In file included from /usr/include/c++/7/unordered_set:48:0,
  from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:118,
  solution.cc:7:
  /usr/include/c++/7/bits/unordered_set.h: In instantiation of ‘class std::unordered_set’:
  solution.cc:119:51: required from here
  /usr/include/c++/7/bits/unordered_set.h:98:63: error: ‘value’ is not a member of ‘std::__not_, std::__detail::__is_noexcept_hash &gt; &gt;’
  typedef __uset_hashtable _Hashtable;
  ^~~~~~~~~~
  /usr/include/c++/7/bits/unordered_set.h:105:45: error: ‘value’ is not a member of ‘std::__not_, std::__detail::__is_noexcept_hash &gt; &gt;’
  typedef typename _Hashtable::key_type key_type;
  ^~~~~~~~ 
  </code></pre>
  
  <p>The error list is much longer, I think this much maybe enough for someone to understand the error. I referred this page for the custom functions : <a href="http://thispointer.com/how-to-use-unordered_set-with-user-defined-classes-tutorial-example/" rel="nofollow noreferrer">http://thispointer.com/how-to-use-unordered_set-with-user-defined-classes-tutorial-example/</a>. Any suggestions? Thanks for reading.</p>
  
  <p>Edit 1: 
  Unordered_set creation:</p>
  
  <pre><code>unordered_set&lt;Node,NodeHasher,NodeComparator&gt; openList;
  </code></pre>
  
  <p>Edit 2:
  Error in comparison operator.</p>
  
  <pre><code>Player 1: compilation error
  In file included from /usr/include/c++/7/bits/stl_algobase.h:71:0,
  from /usr/include/c++/7/vector:60,
  solution.cc:3:
  /usr/include/c++/7/bits/predefined_ops.h: In instantiation of ‘bool __gnu_cxx::__ops::_Iter_equals_val::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator &gt;; _Value = const Node]’:
  /usr/include/c++/7/bits/stl_algo.h:120:14: required from ‘_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator &gt;; _Predicate = __gnu_cxx::__ops::_Iter_equals_val]’
  /usr/include/c++/7/bits/stl_algo.h:161:23: required from ‘_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator &gt;; _Predicate = __gnu_cxx::__ops::_Iter_equals_val]’
  /usr/include/c++/7/bits/stl_algo.h:3907:28: required from ‘_IIter std::find(_IIter, _IIter, const _Tp&amp;) [with _IIter = __gnu_cxx::__normal_iterator &gt;; _Tp = Node]’
  solution.cc:147:73: required from here
  /usr/include/c++/7/bits/predefined_ops.h:241:17: error: no match for ‘operator==’ (operand types are ‘Node’ and ‘const Node’)
  { return *__it == _M_value; }
  ~~~~~~^~~~~~~~~~~
  In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
  from /usr/include/c++/7/vector:60,
  solution.cc:3:
  /usr/include/c++/7/bits/stl_iterator.h:859:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator&amp;, const __gnu_cxx::__normal_iterator&amp;)
  operator==(const __normal_iterator&amp; __lhs,
  ^~~~~~~~
  /usr/include/c++/7/bits/stl_iterator.h:859:5: note: template argument deduction/substitution failed:
  In file included from /usr/include/c++/7/bits/stl_algobase.h:71:0,
  from /usr/include/c++/7/vector:60,
  solution.cc:3:
  /usr/include/c++/7/bits/predefined_ops.h:241:17: note: ‘Node’ is not derived from ‘const __gnu_cxx::__normal_iterator’
  { return *__it == _M_value; }
  ~~~~~~^~~~~~~~~~~
  In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
  from /usr/include/c++/7/vector:60,
  solution.cc:3:
  /usr/include/c++/7/bits/stl_iterator.h:866:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::__normal_iterator&amp;, const __gnu_cxx::__normal_iterator&amp;)
  operator==(const __normal_iterator&amp; __lhs,
  ^~~~~~~~
  /usr/include/c++/7/bits/stl_iterator.h:866:5: note: template argument deduction/substitution failed:
  In file included from /usr/include/c++/7/bits/stl_algobase.h:71:0,
  from /usr/include/c++/7/vector:60,
  solution.cc:3:
  /usr/include/c++/7/bits/predefined_ops.h:241:17: note: ‘Node’ is not derived from ‘const __gnu_cxx::__normal_iterator’
  { return *__it == _M_value; }
  ~~~~~~^~~~~~~~~~~
  In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
  from /usr/include/c++/7/bits/allocator.h:46,
  from /usr/include/c++/7/vector:61,
  solution.cc:3:
  /usr/include/c++/7/ext/new_allocator.h:155:5: note: candidate: template bool __gnu_cxx::operator==(const __gnu_cxx::new_allocator&amp;, const __gnu_cxx::new_allocator&amp;)
  operator==(const new_allocator&amp;, const new_allocator&amp;)
  ^~~~~~~~
  /usr/include/c++/7/ext/new_allocator.h:155:5: note: template argument deduction/substitution failed:
  In file included from /usr/include/c++/7/bits/stl_algobase.h:71:0,
  from /usr/include/c++/7/vector:60,
  solution.cc:3:
  /usr/include/c++/7/bits/predefined_ops.h:241:17: note: ‘Node’ is not derived from ‘const __gnu_cxx::new_allocator’
  { return *__it == _M_value; }
  ~~~~~~^~~~~~~~~~~
  solution.cc: In function ‘std::vector aStar(std::vector &gt;&amp;, std::pair, std::pair)’:
  solution.cc:173:1: error: control reaches end of non-void function [-Werror=return-type]
  }
  ^
  cc1plus: some warnings being treated as errors
  </code></pre>