This compiles:
template <typename... Ts>
void function(std::string name, const Ts&... files) {
// do stuff with Ts, which is NOT ensured to be a child class of std::string
}
According to this answer I wrote the following code in my class:
template <typename Base, typename T, typename... Ts>
struct are_base_of : std::conditional<std::is_base_of<Base, T>::value, are_base_of<Base, Ts...>, std::false_type>::type {};
template <typename Base, typename T>
struct are_base_of<Base, T> : std::is_base_of<Base, T> {};
Now this compiles:
template <typename... Ts>
typename std::enable_if<are_base_of<std::string, Ts...>::value, void>::type
function(std::string name, const Ts&... files) {
// do stuff with Ts, which is ensured to be a child class of std::string
}
This doesn't compile:
template <typename... Ts, typename std::enable_if<are_base_of<std::string, Ts...>::value>>
void function(std::string name, const Ts&... files) {
// do stuff with Ts, which is ensured to be a child class of std::string
}
The error is:
error C3547: template parameter 'unnamed-parameter' cannot be used because it follows a template parameter pack and cannot be deduced from the function parameters of 'MyClass::function'
Why...? And how can I fix it?