![](/img/trans.png)
[英]Why is std::min_element and company not specialized for std::vector<bool>
[英]std::min_element with std::vector<Eigen::Vector2f>
我试图找到 min 元素,如下所示:
#include <algorithm>
#include <iostream>
#include <vector>
#include <Eigen/Dense>
using namespace std;
template<typename T>
bool isLeftOf(const Eigen::Vector2<T>& a,
const Eigen::Vector2<T>& b) {
return (a.x() < b.x() || (a.x() == b.x() && a.y() < b.y()));
}
int main(int argc, char *argv[])
{
std::vector<Eigen::Vector2<float> > points;
points.push_back(Eigen::Vector2<float>(-1, -1));
points.push_back(Eigen::Vector2<float>(1, -1));
points.push_back(Eigen::Vector2<float>(0.5, 0));
points.push_back(Eigen::Vector2<float>(1, 1));
points.push_back(Eigen::Vector2<float>(0, 1.5));
points.push_back(Eigen::Vector2<float>(-1, 1));
points.push_back(Eigen::Vector2<float>(-0.7, 0));
Eigen::Vector2<float> outpointa = min_element(*points.begin(),
*points.end(), isLeftOf<float>);
return 0;
}
但我得到编译器错误:
...\algorithm(9199): error C2675: unary '++': '_FwdIt' 未定义此运算符或转换为具有 [ _FwdIt=Eigen::Matrix<float,2, 的预定义运算符可接受的类型1,0,2,1>]
如何克服这一点?
您需要为 min_element 提供迭代器
这样就可以了,无需取消引用迭代器。
Eigen::Vector2<float> outpointa = min_element(points.begin(),
points.end(), isLeftOf<float>);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.