I have found a code in https://stackoverflow.com/a/36132696/3206356 and I try it. It works, but I don't fully understand what happens there.
I have duplicated code from that link below:
template <size_t N, class = std::make_index_sequence<N>>
class Vector;
template <size_t N, size_t... Is>
class Vector<N, std::index_sequence<Is...>>
{
private:
std::array<double, N> vals;
template <size_t >
using double_ = double;
public:
Vector(double_<Is>... vals)
{
...
}
};
For example, we try to use it next way:
Vector<3> a(1.0, 2.0, 3.0);
How type deduction works here?
p.s.
As I understand when the compiler sees that line, first of all, it tries to deduce types for specialization. It deduces N
as 3 and Is
as empty sequence and then fails when can't find appropriate constructor. General template is not defined, so compilers must fail here too. But what happens next?