|
Boost Users : |
Subject: [Boost-users] [boost-users]Shared_ptr and std::find
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-08-06 21:49:02
Is it possible to have std::find compare the class that the shared_ptr
is pointing too? I have a list of shared_ptr of a class called
FundamentalTypes. The class has it's own operator==. I'd like to
search the list with std::find using the class's operator==. I've
included the class with the key elements I'm referring too.
Ryan
class FundamentalTypes {
public:
FundamentalTypes(std::string const& name) : m_name(name)
bool operator==(FundamentalTypes const& rhs) { return (rhs.m_name ==
m_name) ? true : false; }
std::string m_name;
};
template<typename T>
class Type : public FundamentalTypes {
Type(std::string const& name) : FundamentalTypes(name)
};
//main
typedef shared_ptr<FundamentalTypes> sharedTypes
typedef std::list<sharedTypes> TypesList
sharedTypes value = sharedTypes(new Type<short>("bob"));
TypesList m_list;
TypesList::iterator itor = std::find(m_list.begin(), m_list.end(),
value);
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net