Since it's impossible to store a weak_ptr in a boost::unordered_set / map (as key), I stored a raw pointer instead.
However I revisited the problem today and came up with a dirty hack that worked for me so far:
template<class T> inline bool operator==(weak_ptr<T> const &a, weak_ptr<T> const & b){ return !a._internal_less(b) && !b._internal_less(a);}template<class T> std::size_t hash_value(weak_ptr<T> const & a){ static_assert(sizeof(std::size_t) == sizeof(T*), "std::size_t must have the same size as a pointer"); static_assert(sizeof(weak_ptr<T>) == 2 * sizeof(void*), "Check this hack, the size of weak_ptr has been changed, since the initial implementation"); // Awesome... offsetof cannot acces a private member, therefore I cannot guarantuee that this will even work const T* px = reinterpret_cast<const T*>(*reinterpret_cast<const std::size_t*>(&a)); // Well, you can see in the debugger that both a.px and px have the same value :-) return hash_value(px);}
Unfortunately, I cannot guarantee that px is the first member of weak_ptr which I don't really like. Another problem is the required == operator. Do you know a way to hide it from everything but unordered_set without changing weak_ptr's interface?
I'm aware this is a dirty hack, but at least it's now possible to store an unordered_set<weak_ptr>, so I can avoid raw pointers completely.
*edit*
Do you have any suggestions on this code, perhaps you know of cases when it will most certainly fail.