I have a templated class Foo
that can do identity comparisons (via ==
), but has a function Foo::sameStructureAs(Foo const & other)
for more of a "value" vs. "pointer" notion of equality.
I'd like to make an unordered_map
which overrides the hash function and the equality predicate. They default to std::equal_to<Key>
and std::hash<Key>
...which I provide for my type, based on identity. But I need them to be comparing on the basis of my sameStructureAs
.
Since Foo is a template, I do something like this:
template <class> struct same_structure_as;
template <class> struct hash_structure;
template <class T>
struct hash_structure<Foo<T>>
{
size_t operator() (Foo<T> const & value) const
{
// whatever...
}
};
template <class T>
struct same_structure_as<Foo<T>>
{
bool operator() (Foo<T> const & left, Foo<T> const & right) const
{
// whatever...
}
};
Which seems like I'm following roughly the strategy of the classes in std::
for this purpose, and creating something general. So does that look right?
Secondly: Is there any precedent for the naming of this or a prototype already existing in std::? I've thought about words like isomorphic
or congruent
. It seems like something that would come up often in designing classes when you have more than one idea of what it means to be "equal".