Suppose you have a set of pointers (yeah...) :
std::set<SomeType*> myTypeContainer;
Then suppose that you want to search this set from a const method of SomeType:
bool SomeType::IsContainered() const
{
return myTypeContainer.find(this) != myTypeContainer.end();
}
This doesn't work. The this
ptr in the method is a const SomeType *const
, which I can't put into the find
. The issue being that find
takes a const-ref, which in this case would mean that the passed pointer is treated as const, but not the thing it points to.
Is there a way to resolve this smoothly (without changing the set template type)?