I've been trying to implement checking to see if a type is a specialization of a specific template. I have seen quite a few answers online, but most of them only work for type parameters.
I found this SO answer that does cover non-type parameters. However, it is undesirable since it wraps them in a struct which is making it very difficult to create a concept for it. It also requires explicitly specifying the non-type template parameters.
I have come up with the following that comes from the answers I've seen online. But for the non-type version, I would have to create a new version for each parameter type (I've used bool... below as an example).
template <template <typename...> typename C, typename T> struct type_instance_impl : public std::false_type {};
template <template <typename...> typename C, typename...T> struct type_instance_impl<C, C<T...>> : public std::true_type {};
template <template <typename...> typename C, typename T> concept instance_of_type = type_instance_impl<C, std::decay_t<T>>::value;
template <template <bool ...> typename C, typename T> struct non_type_instance_impl : public std::false_type {};
template <template <bool ...> typename C, bool ...T> struct non_type_instance_impl<C, C<T...>> : public std::true_type {};
template <template <bool ...> typename C, typename T> concept instance_of_non_type = non_type_instance_impl<C, std::decay_t<T>>::value;
Usage:
template <bool...> class bools;
int main(){
std::cout << instance_of_type<std::complex, std::complex<double>>;
std::cout << instance_of_non_type<bools, bools<true, false, true>>;
return 0;
}
Is there a solution that will allow for any non-type parameter (and any amount of parameters)?
I would also like if both the type and non-type version could be combined into a single concept but that isn't necessary.