Unlike auto
, where a braced-init-list is deduced as an initializer_list
, template argument deduction considers it to be a non-deduced context, unless there exists a corresponding parameter of type initializer_list<T>
, in which case the T
can be deduced.
From §14.8.2.1/1 [temp.deduct.call] (emphasis added)
Template argument deduction is done by comparing each function template parameter type (call it
P
) with the type of the corresponding argument of the call (call itA
) as described below. If removing references and cv-qualifiers fromP
givesstd::initializer_list<P0>
for someP0
and the argument is an initializer list (8.5.4), then deduction is performed instead for each element of the initializer list, takingP0
as a function template parameter type and the initializer element as its argument. Otherwise, an initializer list argument causes the parameter to be considered a non-deduced context (14.8.2.5).
Thus the argument to your operator=
is not deduced to be an initializer_list<double>
. For the code to work, you must define an operator=
that takes an initializer_list
argument.
template <typename U>
self& operator= ( const std::initializer_list<T>& other )
{
if ( other.size() == N )
std::copy_n( other.begin(), N, m_data );
return *this;
}