Bug 664 - not all iterator support operator<
not all iterator support operator<
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Sparse
3.2
x86 - 64-bit Linux
: Normal Unknown
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-09-27 09:32 UTC by facat
Modified: 2013-10-16 13:41 UTC (History)
1 user (show)



Attachments

Description facat 2013-09-27 09:32:16 UTC
Recently I compiled my program with Eigen 3.2 stable and encouterd an error as follow:

error: no match for ‘operator<’ (operand types are ‘const std::_List_iterator<Eigen::Triplet<double> >’ and ‘const std::_List_iterator<Eigen::Triplet<double> >’)

This is caused by comparing "begin" end "end" in function set_from_triplets in SparseMatrix.h

"begin" and "end" are two iterator variable. This error is due the fact that iterator of std::list doesn't support < operation. This bug was introduced by the 9e8ce09 commit for "Fix setFromTripplet with empty inputs". We know that many containers support iterator, but not all their iterators support operator<. std::list is the case. To my best knowledge, all iterators support operator!=. 
I think operator!= is more general to check if a container is empty.

The example below can reprduce the error

///////////////////////////////////
#include <iostream>

#include <Eigen/Sparse>
#include <list>

using namespace std;

int main()
{
    Eigen::SparseMatrix<double> mat(3,3);
    std::list<Eigen::Triplet<double> > t;
    t.push_back(
    Eigen::Triplet<double>(0,0,1)
    );

    mat.setFromTriplets(t.begin(),t.end());
    return 0;
}

////////////////////////////////

I compiled my code under linux Mint 64bit with gcc 4.8.1.
Comment 1 Christoph Hertzberg 2013-10-16 13:41:56 UTC
Fixed and backported to 3.2 here:
https://bitbucket.org/eigen/eigen/commits/961ac1984b0fd685bb9becc18674008897562d28

Note You need to log in before you can comment on or make changes to this bug.