I have a class that has a private std::vector and uses it to store its
content. I want to search the data within this vector and return the
size_t index of that data.
Pseudo-code:
class Foo
{
public:
std::string name;
int otherData;
};
inline bool operator==( const Foo& f, const std::string& name )
{
return f.name.compare(name) == 0;
}
class Manager
{
public:
size_t getIDFor( const std::string& name )
{
std::vector<RotamerSet>::const_iterator findResult = std::find(
m_Data.begin(), m_Data.end(), name );
// How do I return a size_t from an itterator ?!?
return 0;
}
private:
std::vector<Foom_Data; // The data, the manager garantees that this
contains only ONE of each named foo
};
1) How do I return a size_t from the itterator ?!?
2) Is std::find more efficient than manually itterating the vector and
performing the == test sequentially?
Many thanks
Jon