I am trying to define the following:
#include <tr1/unordered_set>
#include <tr1/unordered_map>
template <class T> class cnf
{
public:
T x;
bool operator==(const cnf& c) { c.x == x; }
size_t hash(const cnf& c) { return x.hash(); }
}
template <class T> class cnf_table {
private:
typedef unordered_set<cnf<T> > cnf_set;
typedef unordered_map<T, cnf<T> > cnf_map;
cnf_map my_map;
}
and I have the following problems:
I am not sure the == and hash will actually be used when I defined this way the unordered_set and unordered_map, will they?
A more severe problem, I don't think this compiles because you can't call x.hash() for an incomplete type T -- is there a different way to define the hash?
When I try to compile something like that I get ton of chain errors, referring to STL include files, finally with something along the lines:
file.h:67: instantiated from here /usr/include/c++/4.2.1/tr1/hashtable_policy.h:784: error: using invalid field βstd::tr1::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, _H1, H2, std::tr1::_detail::_Default_ranged_hash, false>::_M_h1β
EDIT: About 2, what I am uncertain about is how to use in a template environment the hash value of a type T. I think that for a type T, you can't call a method directly, so I am not sure how to calculate its hash code.