visual studio 2017 15.9.13 无法使用自动 C++ 模板

visual studio 2017 15.9.13 can't use auto c++ templates

我大约一个小时前安装了 visual studio 2017 for c++ desktop 和 linux development 我尝试了这段使用 c++17 自动模板的代码,但很惊讶它给出了一个错误:

Error C3533 a parameter cannot have a type that contains 'auto'

这是导致问题的代码

template <class T, T null_value, bool no_negative, auto Deleter>
struct HandleHelper
{
    using pointer = HandleWrapper<T, null_value, no_negative>;
    void operator(pointer p)
    {
        Deleter(p);
    }
};

在 visual studio 2015 年之前,由于缺少 c++17 支持,我使用了类似的东西:

template <class T, T null_value, bool no_negative, class DelType, DelType Deleter>
struct HandleHelper
{
    using pointer = HandleWrapper<T, null_value, no_negative>;
    void operator(pointer p)
    {
        Deleter(p);
    }
};

但自动模板看起来更优雅

确保您在项目的 属性 页面中设置了正确的 "C++ Language Standard"。 VS 2017 的默认值为 C++14.

右键单击您的项目并 select "Properties"。 然后在左侧的树视图中展开 C/C++ 节点。 Select "Language" 来自展开的菜单选项。 检查 "C++ Language Standard" 是否设置为 ISO C++17 Standard (/std:c++17)

如果为空,则默认为C++14

您需要在 VS2017 中打开 C++17 支持。 By default VS2017 uses C++14 用于新项目。要打开 C++17,请在命令行中使用 /std:c++17 或转到项目 -> 属性 -> 语言 -> C++ 语言标准和 select /std:c++17

您也可以使用 /std:c++latest 并获得最多 date/experimental 支持