简体   繁体   English

用C ++ 17编译Eigen需要_SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING定义

[英]Compiling Eigen with C++17 needs _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING definition

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. 似乎eigen使用的函数已被弃用,我可以用一些定义修复它。 However, I am usure whether or not I SHOULD add these definitions to a project or wait for a newer version of Eigen. 但是,无论我是否应该将这些定义添加到项目中或等待更新版本的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. 1> d:\\ eigen_3.3.4 \\ eigen \\ src \\ core \\ functors \\ stlfunctors.h(87):错误C4996:'std :: unary_negate <_Fn>':警告STL4008:std :: not1(),std ::在C ++ 17中不推荐使用not2(),std :: unary_negate和std :: binary_negate。 They are superseded by std::not_fn(). 它们被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. 您可以定义_SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING或_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS以确认您已收到此警告。 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. 1> d:\\ eigen_3.3.4 \\ eigen \\ src \\ core \\ functors \\ stlfunctors.h(91):错误C4996:'std :: binary_negate <_Fn>':警告STL4008:std :: not1(),std ::在C ++ 17中不推荐使用not2(),std :: unary_negate和std :: binary_negate。 They are superseded by std::not_fn(). 它们被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. 您可以定义_SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING或_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS以确认您已收到此警告。 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> 1> d:\\ sandbox \\ sandbox.cpp(25):错误C2678:二进制'<<':找不到带有'Eigen :: Block'类型左手操作数的运算符(或者没有可接受的转换)1 > 1> [1> Derived = Eigen :: SparseMatrix 1>

Thanks in advance! 提前致谢!

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. 首先,您应该在C ++ 14模式下编译,或者按照说明定义_SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING

Secondly, the line m.block(0, 0, 2, 2) << 1, 2, 3, 4; 其次,行m.block(0, 0, 2, 2) << 1, 2, 3, 4; is not valid for a SparseMatrix . SparseMatrix I don't know what you want to achieve, but unless you really known what you are doing (ie, 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 . 我不知道你想要实现什么,但除非你真的知道你在做什么(即你的代码在内存重新分配和重新复制方面意味着什么),你应该坚持通过三元组列表组装SparseMatrix按照文档的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM