【发布时间】:2015-02-25 10:49:38
【问题描述】:
我有一个 x,y,z 值的排序 std::vector<std::vector<double>>,如下所示,
0.0, 0.0, 0.0
0.0, 0.0, 0.1
0.0, 0.0, 0.2
0.0, 0.1, 0.0
0.0, 0.2, 0.1
0.0, 0.2, 0.3
我想查找特定 x 和 y 值的所有 z 值, ex - z 值 0.0, 0.0, 应该返回
0.0, 0.0, 0.0
0.0, 0.0, 0.1
0.0, 0.0, 0.2
我尝试过使用
struct MatchDouble
{
MatchDouble(double _x,double _y) : x(_x), y(_y) {}
bool operator()(std::vector<double> &n)
{
return fabs(x - n[0]) < FLT_EPSILON && fabs(y - n[1]) < FLT_EPSILON;
}
private:
double x, y ;
};
it = find_if(allpoints.begin(), allpoints.end(),MatchDouble(0.0,0.0));
但这只会给我一个指向单个向量值的迭代器。什么方法最适合实现这一目标?
谢谢。
【问题讨论】:
-
如果您不想复制元素或检查其他答案是否更符合您的要求,您可以使用 this simple
for_each_if包装器。
标签: c++ vector stl containers