I'm trying to initialize my Matrix
class with std::initializer_list
s. I know I can do it with std::index_sequence
, but I don't know how to expand them in one statement.
This is how I do it:
template<size_t rows, size_t cols>
class Matrix {
public:
Matrix(std::initializer_list<std::initializer_list<float>> il)
: Matrix(il,
std::make_index_sequence<rows>(),
std::make_index_sequence<cols>()) {}
private:
template<size_t... RowIs, size_t... ColIs>
Matrix(std::initializer_list<std::initializer_list<float>> il,
std::index_sequence<RowIs...>,
std::index_sequence<ColIs...>)
: values_{
{
il.begin()[RowIs].begin()[ColIs]...
}...
} {}
public:
float values_[rows][cols] = {};
};
It fails on the second expansion with error Pack expansion does not contain any unexpanded parameter packs
. Maybe I can somehow specify which parameter pack I want to expand?
Hope for your help!