Skip to content

const_iterator vs iterator compilation error

Submitted by w.h..@..il.com

Assigned to Nobody

Link to original bugzilla bug (#1619)
Version: 3.4 (development)

Description

I was experimenting with the new STL-compatible iterator capability using VS 2017. The following code snippet compiles correctly:

const int n = 6;

typedef Eigen::VectorXd V;

V v(n);

v << 1, 4, 6, 17, 33, 8;

cout << v.transpose() << endl;

for (V::iterator it = v.begin(); it != v.end(); ++it)

cout << *it << ", ";  

However, if I replace V::iterator with V::const_iterator, VS produces these

compilation errors:

1>------ Build started: Project: eigenXTests, Configuration: Debug x64 ------

1>eigenXTests.cpp

1>c:\wgreene\tests\c++\vs2017tests\eigenxtests\eigenxtests.cpp(18): error C2440: 'initializing': cannot convert from 'Eigen::internal::pointer_based_stl_iterator<Derived>' to 'Eigen::internal::pointer_based_stl_iterator<const Derived>'

1> with

1> [

1> Derived=Eigen::Matrix<double,-1,1,0,-1,1>

1> ]

1>c:\wgreene\tests\c++\vs2017tests\eigenxtests\eigenxtests.cpp(18): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

1>c:\wgreene\tests\c++\vs2017tests\eigenxtests\eigenxtests.cpp(18): error C2679: binary '!=': no operator found which takes a right-hand operand of type 'Eigen::internal::pointer_based_stl_iterator<Derived>' (or there is no acceptable conversion)

1> with

1> [

1> Derived=Eigen::Matrix<double,-1,1,0,-1,1>

1> ]

1>c:\wgreene\src\eigen\eigen-3.3.x\eigen\src\core\stliterators.h(96): note: could be 'bool Eigen::internal::pointer_based_stl_iterator<const Derived>::operator !=(const Eigen::internal::pointer_based_stl_iterator<const Derived> &)'

1> with

1> [

1> Derived=Eigen::Matrix<double,-1,1,0,-1,1>

1> ]

1>c:\wgreene\tests\c++\vs2017tests\eigenxtests\eigenxtests.cpp(18): note: while trying to match the argument list '(Eigen::internal::pointer_based_stl_iterator<const Derived>, Eigen::internal::pointer_based_stl_iterator<Derived>)'

1> with

1> [

1> Derived=Eigen::Matrix<double,-1,1,0,-1,1>

1> ]

1>Done building project "eigenXTests.vcxproj" -- FAILED.

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Blocking

#814