I am trying to define a type trait that I can use with static_assert
to control that one of my template classes is instantiated only with std::array<T,n>
. Here is my attempt:
template <typename T>
struct is_std_array : public false_type {};
template <template <typename, size_t> class T, typename V, size_t n>
struct is_std_array<std::array<V, n>> : public true_type {};
But I get the following warning from clang:
warning: class template partial specialization contains a template parameter
that cannot be deduced; this partial specialization will never be used
non-deductible template parameter 'T'
Why is 'T' not deductible? How do I fix that?
Your syntax on specializing is wrong:
template <template <typename, size_t> class T, typename V, size_t n>
You're introducing three template parameters here: the first of which is a template template parameter named T
, that takes two parameters: a type and a size_t
. Since T
is not referenced anywhere in your specialization clause:
struct is_std_array<std::array<V, n>> // <== no T
it's a non-deduced context. Think of the equivalently written function:
template <template <typename, size_t> class T, typename V, size_t n>
void foo(std::array<V, n> );
Here, also, T
is a non-deduced context and so would have to be specified explicitly. However, you don't actually need T
at all! Just V
and n
. What you mean is to simply introduce the two relevant parameters directly:
template <typename V, size_t n>
struct is_std_array<std::array<V, n>> : public true_type {};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With