Код: Выделить всё
template
struct A { T t[2]; };
Код: Выделить всё
constexpr A a{ { {1}, 2.5 } };
static_assert( a.t[0] == 1. && a.t[1] == 2.5 );
Код: Выделить всё
warning: braces around scalar initializer [-Wbraced-scalar-init]
warning: extra braces are nonstandard
И только MSVC отклоняет программу с ошибкой:
Код: Выделить всё
(5): error C2641: cannot deduce template arguments for 'A'
(5): note: 'A A(const double (&)[2])': cannot convert argument 1 from 'initializer list' to 'const double (&)[2]'
...
Код: Выделить всё
constexpr A b( { {1}, 2.5 } );Код: Выделить всё
:9:29: error: class template argument deduction failed:
:9:29: error: no matching function for call to 'A(
)'
:9:29: note: there are 3 candidates
...
:2:8: note: candidate 3: 'A(T [2]) -> A [with T = double]'
:2:8: note: no known conversion for argument 1 from '
' to 'double*
Какая реализация здесь правильная?
Мобильная версия