dev65
dev65

Reputation: 1605

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

I installed visual studio 2017 for c++ desktop and linux development some about an hour ago I tried this code which uses c++17 auto templates and was surprised that it gives an error saying :

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

this is the code causing the problem

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);
    }
};

before in visual studio 2015 I used something like this due to lack of c++17 support :

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);
    }
};

but auto templates looks more elegant

Upvotes: 1

Views: 537

Answers (2)

NathanOliver
NathanOliver

Reputation: 181027

You need to turn on C++17 support in VS2017. By default VS2017 uses C++14 for new projects. To turn on C++17 either use /std:c++17 in the command line or go to Project -> Properties -> Language -> C++ Language Standard and select /std:c++17

You can also use /std:c++latest and get the most up to date/experimental support

Upvotes: 1

WBuck
WBuck

Reputation: 5511

Make sure you have the correct "C++ Language Standard" set in the property pages for your project. The default for VS 2017 is C++14.

Right click on your project and select "Properties". Then expand the C/C++ node on the tree view on the left hand side. Select "Language" from the expanded menu options. Check that the "C++ Language Standard" is set to ISO C++17 Standard (/std:c++17).

If its blank, it will default to C++14.

Upvotes: 3

Related Questions