I have an unordered_set<shared_ptr<T>> us
and I would like to know whether a needle k
is in us
, but k
has type shared_ptr<T const>
so unordered_set<shared_ptr<T>>::find
complains that it cannot convert.
Is there a way around this? Maybe by directly supplying the hash?
I did try const_cast
(and felt dirty) but that didn't cut it.
shared_ptr<T>
andshared_ptr<T const>
own the same object, won't you have 2 owner blocks for the different object types? – Harijanshared_ptr<T>
toshared_ptr<T const>
that does the right thing. But also, you can even haveshared_ptr<T>
andshared_ptr<int>
share ownership, using the aliasing constructors. (That might be used to produce a shared pointer to a member of a class which is owned by a shared pointer. When the last pointer sharing ownership is destroyed, the original deleter is called, ignoring the type of the last shared pointer.) – Thrifty