Stack Exchange
Template function with a parameter of type 'const C s[N]' (fixed size array of elements of type C)
How to make the following code compile?
    template <typename C, size_t N>
    constexpr uint64_t cs_hash(const C s[N])
    {
        return N;
    }

    constexpr char sample[] = "communism";

    constexpr uint64_t h = cs_hash(sample);

The compiler error with MSVC 2017 is
error C2784: 'uint64_t cs_hash(const C [N])': could not deduce template argument for 'const C [N]' from 'const char [10]'


Use a const reference!
template <typename C, size_t N>
constexpr uint64_t cs_hash(const C (&s)[N])
{
    return N;
}


Explanation
When you attempt to create a function parameter of type T [] or T [N], compiler automatically replaces the type with T *.
It means that your function declaration is no different from
template <typename C, size_t N>
constexpr uint64_t cs_hash(const C *s)
{
    return N;
}

Since the parameter type doesn't depend on N, there is no way for N to be deduced.
But when you use a 'reference to array' parameter, said rule for array parameters doesn't apply, and nothing stops the deduction from working properly.
