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.
Using std::const_pointer_cast
is a possible solution here.
us.find(std::const_pointer_cast<T>(k));
Since you're not modifying k
, it's okay to cast away the const.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With