如何在Visual Studio C ++ 17中还原auto_ptr [英] How to restore auto_ptr in Visual Studio C++17
问题描述
此博客页面提到Visual Studio删除了一些标准功能:
This blog page mentions that Visual Studio removes some std features:
https://blogs.msdn.microsoft.com/vcblog/2017/12/08/c17-feature-removals-and-deprecations/
我有一个项目,该项目使用了一些现在使用C ++ 17功能的C ++库.该项目还使用了第三方库websocketpp( https://github.com/zaphoyd/websocketpp )仍然使用一些现在已删除的功能.例如auto_ptr和binary_function.我收到编译器错误,指出它们不是'std'的成员.
I have a project that consumes some C++ libraries that now use C++17 features. The project also consumes a third party library websocketpp (https://github.com/zaphoyd/websocketpp) that still uses some now removed features. eg auto_ptr and binary_function. I'm getting compiler errors that they are not a member of 'std'.
以上博客提到,可以使用细粒度控件来恢复已删除的功能.我想我可以用它来使这个项目现在编译.从长远来看,我会看到有关将websocketpp升级到C ++ 17或用其他替换它的事情.
The blog above mentions that removed features can be restored using a fine grain control. I'm thinking I could use that to get this project to compile for now. Longer term I will see about upgrading websocketpp to C++17 or replacing it with something else.
但是,恢复功能的神奇之处是什么?我需要#define吗?如果是这样,怎么办?
But, what is the magic to restore features? Is there something I need to #define? If so, what?
推荐答案
在VS2017 v15.5中,基于项目的/std:c ++ 17设置,有条件地将其排除在外.您可以通过强制基础宏值来强制将其包括在内.两种基本方法可以做到这一点:
In VS2017 v15.5 it is conditionally excluded, based on the project's /std:c++17 setting. You can force it to be included by forcing the underlying macro value. Two basic ways to do this:
- 项目>属性> C/C ++>预处理程序>预处理程序定义,然后添加
_HAS_AUTO_PTR_ETC = 1
.对所有配置和平台都这样做. - 如果您使用预编译的标头,则可能希望在此定义宏.在任何#include之前,插入
#define _HAS_AUTO_PTR_ETC 1
.
- Project > Properties > C/C++ > Preprocessor > Preprocessor Definitions and add
_HAS_AUTO_PTR_ETC=1
. Do so for all configurations and platforms. - If you use a precompiled header then you probably favor defining the macro there. Before any #includes, insert
#define _HAS_AUTO_PTR_ETC 1
.
当心"ETC",您还将设置已弃用的random_shuffle()和unary_function<>.预测未来很困难,但这可能会在未来一段时间发挥作用.
Beware of the "ETC", you'll also slurp the deprecated random_shuffle() and unary_function<>. Predicting the future is difficult, but this is probably going to work for a while to come.
这篇关于如何在Visual Studio C ++ 17中还原auto_ptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!