Compilation error in dev branch when a struct is used as a vector/matrix index
We have a code that is currently working great with Eigen 3.3.7, and I wanted to use the new slicing features in the development branch that are planned for 3.4. But compilation of our code fails on the dev branch. I am not an expert in Eigen, so here is the minimum code to reproduce it ( I did it on https://godbolt.org/ with different compilers).
#include <Eigen/Core>
#include <iostream>
struct IndexType
{
IndexType( int idx ) : mIndex( idx ) {}
int mIndex;
operator int () const { return mIndex; }
int index() const { return mIndex; }
};
int main(){
Eigen::Vector3d vec = Eigen::Vector3d::Zero();
const IndexType index_1 = 1;
// working
std::cout<< vec( index_1.index() ) <<std::endl;
// working
std::cout<< vec[ index_1 ] <<std::endl;
// working for eigen 3.3.7, but not for current branch
std::cout<< vec( index_1 ) <<std::endl;
}
My guess is that for the line vec( index_1 ), Eigen considers the struct index_1 as a range ( feature added recently in the dev branch to facilitate slicing operations), overriding the conversion operator operator int ().
Edited by Florian Maurin