Hi,
I have some user-defined classes, for which I have to define std::hash, which are nested in the scope of another user-defined class. So I have to specialize hash<> for those. The problem is that:
1-) I cannot do the specialization before the outer class declaration, because if template parameters are classes then they should be fully declared previously (forward declaration does not work).
2-) I cannot do the specialization after the outer class declaration, because I'm using the specialized hash<> classes within the scope of the outer class declaration and I'm getting a 'specialization after instantiation' error by the compiler.
3-) I cannot do the specialization within the scope of the outer class, because hash<> is defined in namespace std and the compiler gives the error that template is specialized in non-namespace scope. When I try to enclose the specializations with
namespace std {}
It gives me a weird error saying that "expected unqualified-id before ‘namespace’".
So I'm stuck, and I don't know how to do these specializations. My full code is too long to include but here are the snippets relevant to the problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
class BPCFGParser {
public:
...
...
class Edge {
...
...
};
class ActiveEquivClass {
...
...
};
class PassiveEquivClass {
...
...
};
struct EqActiveEquivClass {
...
...
};
struct EqPassiveEquivClass {
...
...
};
unordered_map<ActiveEquivClass, Edge *, hash<ActiveEquivClass>, EqActiveEquivClass> discovered_active_edges;
unordered_map<PassiveEquivClass, Edge *, hash<PassiveEquivClass>, EqPassiveEquivClass> discovered_passive_edges;
};
|
In this code I'm trying to specialize std::hash<> for ActiveEquivClass and PassiveEquivClass. I'm working with g++ on Linux, with -std=gnu++0x option. Any help will be highly appreciated. Thanks.