简体   繁体   中英

std::min_element with std::vector<Eigen::Vector2f>

I'm trying to find the min element as follows:

#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;
}

But I get compiler error:

...\algorithm(9199): error C2675: unary '++': '_FwdIt' does not define this operator or a conversion to a type acceptable to the predefined operator with [ _FwdIt=Eigen::Matrix<float,2,1,0,2,1> ]

How to overcome this?

you need to provide iterators to min_element

this will do, no need to dereference the iterators.


Eigen::Vector2<float> outpointa = min_element(points.begin(),
                                                points.end(), isLeftOf<float>);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM