我确信我让这件事变得比需要的更加困难。
我有一个向量...
vector<Joints> mJointsVector;
...由以下结构组成:
struct Joints
{
string name;
float origUpperLimit;
float origLowerLimit;
};
我正在尝试使用“std::find”搜索 mJointsVector 以通过其字符串名称来定位单个关节 - 到目前为止还没有运气,但以下示例至少在概念上有所帮助:
向量、结构和 std::find https://stackoverflow.com/questions/589985/vectors-structs-and-stdfind
谁能进一步指出我正确的方向?
一种直接的方法:
struct FindByName {
const std::string name;
FindByName(const std::string& name) : name(name) {}
bool operator()(const Joints& j) const {
return j.name == name;
}
};
std::vector<Joints>::iterator it = std::find_if(m_jointsVector.begin(),
m_jointsVector.end(),
FindByName("foo"));
if(it != m_jointsVector.end()) {
// ...
}
或者你可能想看看类似的东西升压绑定 http://www.boost.org/doc/libs/1_41_0/libs/bind/bind.html以减少代码量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)