im having a problem with std::set
ive got different sets where all the types inherit a class "Identifiable" with an std::string Id() function...
looks somehting like this
struct IDCompare
{
bool operator()(const IdentifiablePtr& lhs, const IdentifiablePtr& rhs) const
{
return strcmp(lhs->Id().c_str(), rhs->Id().c_str()) < 0 ;
}
};
std::set<boost::shared_ptr<SomeType>, IDCompare>
however when i want to find an object in the set based on the "Id" i get into problems...
template<typename T>
boost::shared_ptr<T> Find(const std::string& id) const
{
boost::shared_ptr<T> dummy(new T(id));
SetType::const_iterator it = mySet.find(dummy);
return it != Get<T>().end() ? *it : boost::shared_ptr<T>();
}
i have to create a "dummy" object of the type in order to find the real object... these objects can be pretty large so i dont want to create a dummy everytime...
the reason im using a set instead of a map is that i want to be able to use for_each functions and similar easily...
how shoudl i go about this?