I learned about c++17'sauto
template parameters in the answer to this question. A coworker had informed me that they were supported on visual-studio-2017, but I seem to have been less than successful in my attempt to utilize this functionality. I've written this toy example to demonstrate my problem:
struct Foo {
int mem;
};
template <auto T>
decltype(T(Foo{})) bar(const Foo& param)
{
return T(param);
}
int func(const Foo& param) { return param.mem; }
int main() {
Foo myFoo{ 13 };
cout << bar<&func>(myFoo);
}
I believe this to be good code as it works fine on gcc In Visual Studio however I get this:
error C3533: a parameter cannot have a type that contains
auto
I've ensured that my "C++ Language Standard" set to: "ISO C++ Latest Draft Standard (/std:c++latest)" but that doesn't seem to solve the problem. Visual Studio will support the pre-auto
template parameter code which requires I pass the function type along with the function as template arguments: template <typename R, R(*T)(const Foo&)> R bar(const Foo& param)
But this doesn't match the elegance of the auto
template parameter.
Is there a way that I can either help Visual Studio compile the auto
template code or manage similar elegance while still compiling on visual-studio-2017?