I have a template that takes a template template parameter and a pack of type arguments. I want to instantiate the template with the arguments only if the arities match. Something like this:
// can_apply_t = ???
template<template<typename...> typename Template, typename... Args>
struct test {
using type = std::conditional_t<can_apply_t<Template, Args...>, Template<Args...>, void>;
};
template<typename> struct unary_template;
template<typename, typename> struct binary_template;
static_assert(std::is_same_v< test<unary_template, int>::type, unary_template<int> >);
static_assert(std::is_same_v< test<binary_template, int>::type, void >);
I fantasized that it would be as simple as this:
template<template<typename... T> typename Template, typename... Args>
struct test {
using type = std::conditional_t<sizeof...(T) == sizeof...(Args), Template<Args...>, void>;
};
...but clang++12 says:
error: 'T' does not refer to the name of a parameter pack