Registered Member
|
Hi everyone,
this is my first post here and first I need to say what a great library Eigen is! Today, however, I stumbled upoon a problem I could not solve. I am currently trying to sort an std::vector<Eigen::Vector3d> via std::sort. In order for that to happen I need a binary comparison function I can pass to std::sort. I want to sort by comparing the first coefficient. If one is greater than the other -> return; if they are the same (within epsilon), check the second coefficient and so on. So I tried template recursion like this:
with a specialization for i == 1 of course. However, this does not compile (gcc 4.6). It seems like the compiler cannot instantiate the compX.tail<i - 1> () template. My guess is, that that is because it can't deduce Matrix<T, i, 1> to be a vector-only type, but of course I might be wrong. Can anyone help me on this issue or are there any other ways of comparing Vectors? Best regards, Matze |
Moderator
|
classic mistake, you have to add the template keywords:
comp1.template tail<i - 1> () |
Registered Member
|
Thank you very much, I did not know, that was actually possible. But using .tail <>() was a stupid idea anyway sicne it creates a new Vector for every step of the recursion ...
In case anybody needs this, here iy my working code:
One can pass i.e. aSmallerB<3, double> directly to std::sort or std::lower_bound. Best regards Matze |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]