I have a function where a template type parameter follows a parameter pack. It looks like this:
template<typename...Args, typename T>
T* default_factory_func()
{
return new T;
}
Visual C++ compiler rejects it with an error C3547: template parameter 'T' cannot be used because it follows a template parameter pack and cannot be deduced from the function parameters of 'default_factory_func'.
However, I tried various versions of GCC (starting with 4.4.7) and clang (starting with 3.1) available on Compiler Explorer, and all of them compile such code just fine.
// this code is just a minimal example condensed
// from a much more complex codebase
template<typename T>
T* construct(T* (*factory_func)())
{
return factory_func();
}
template<typename...Args, typename T>
T* default_factory_func() // C3547 on this line
{
return new T(Args()...);
}
struct some_class {
some_class(int, int, int) {}
};
int main()
{
construct<some_class>(
default_factory_func<int,int,int>
);
}
Is this some quirk of MSVC or is it not allowed by the standard?