Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Eigen with C++17 needs _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING definition

Tags:

c++

c++17

eigen

I am trying to asign a block of a sparse matrix and canot get it to work. It seems a function used by eigen is deprecated and I could fix it with some definitions. However, I am usure whether or not I SHOULD add these definitions to a project or wait for a newer version of Eigen. Could you guys advice on the side-effects of the definitions.

The program I wrote looks like this

#include <Eigen/Sparse>

int main()
{
    Eigen::SparseMatrix<double> m(4, 4);

    m.block(0, 0, 2, 2) << 1, 2, 3, 4;
}

and this is the warning:

1>d:\eigen_3.3.4\eigen\src\core\functors\stlfunctors.h(87): error C4996: 'std::unary_negate<_Fn>': warning STL4008: std::not1(), std::not2(), std::unary_negate, and std::binary_negate are deprecated in C++17. They are superseded by std::not_fn(). You can define _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning. 1>d:\eigen_3.3.4\eigen\src\core\functors\stlfunctors.h(91): error C4996: 'std::binary_negate<_Fn>': warning STL4008: std::not1(), std::not2(), std::unary_negate, and std::binary_negate are deprecated in C++17. They are superseded by std::not_fn(). You can define _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning. 1>d:\sandbox\sandbox.cpp(25): error C2678: binary '<<': no operator found which takes a left-hand operand of type 'Eigen::Block' (or there is no acceptable conversion) 1> with 1> [ 1> Derived=Eigen::SparseMatrix 1>

Thanks in advance!

like image 828
Petter Muff Avatar asked Sep 16 '18 20:09

Petter Muff


1 Answers

There are two very different issues here. Firstly, you should either compile in C++14 mode or define _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING as told.

Secondly, the line m.block(0, 0, 2, 2) << 1, 2, 3, 4; is not valid for a SparseMatrix. I don't know what you want to achieve, but unless you really known what you are doing (i.e., what your code will imply in terms of memory reallocation and re-copies), you should stick with assembling a SparseMatrix through a triplet list as recommended by the doc.

like image 136
ggael Avatar answered Nov 18 '22 06:11

ggael