Compiling Eigen with C++17 needs _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING definition
Asked Answered
M

1

6

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!

Medwin answered 16/9, 2018 at 20:4 Comment(0)
I
6

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.

Ierna answered 16/9, 2018 at 20:20 Comment(1)
Oh, great! I didn't know! This solves the issues even voids the need to define stuff ;)Medwin

© 2022 - 2024 — McMap. All rights reserved.