Initialize a class with brace-enclosed initializer list
<p>I'm trying to initialize a class Vec with a brace-enclosed initializer list, to be called like in this minimal example:</p>

<pre><code>int main()
{
    Vec&lt;3&gt; myVec1{{1,2,3}}; // or: myVec1({1,2,3});
    Vec&lt;3&gt; myVec2;
    myVec2 = {1, 2, 3};
    Vec&lt;3&gt; myVec3 = {1,2,3};
    return 0;
}
</code></pre>

<p>All these initializations (and the assignment) should work. (Plus custom default constructor. Using an aggregate class is thus impossible.)</p>

<p>While I could just use a std::initializer_list like such:</p>

<pre><code>template &lt;unsigned C&gt;
struct Vec
{
    Vec(){}
    Vec(std::initializer_list&lt;int&gt; list)
    {
        //does not work for obvious reasons:
        //static_assert(list.size() == C, "");
    }
};
</code></pre>

<p>I can't statically ensure the number of parameters to be equal to my template parameter, i.e., an initialization with {1, 2, 3, 4} would only fail during runtime.</p>

<p>Browsing SO, I came up with the following:</p>

<pre><code>template &lt;unsigned C&gt;
struct Vec
{
    Vec(){}
    Vec(const unsigned(&amp;other)[C]){}
    Vec&amp; operator=(const unsigned(&amp;other)[C]){return *this;}
};
</code></pre>

<p>This works fine for the assignment and () or {} initialization (as for myVec1) - but it fails for the initialization using = (as for myVec3). </p>

<p>(GCC gives error "could not convert '{1, 2, 3}' from '' to 'Vec&lt;3u>'")</p>

<p>I don't get why one of the initializations should work, but not the other.
Any other ideas how I can use the brace-enclosed initializer list, but also ensure the correct length at compile time?</p>

<p>Thanks :)</p>